After reading a little of this back and forth of annotations,
validation and documentation (oh my). I thought, why not just abstract
the standard types (string, int, bool, etc...) to SPL classes.

This would allow for validation, documentation, casting, and related
functions ( length, substr, etc...) to be encapsulated in the class,
rather than in some new language construct.

This is a bit .NETish, but each instance of a variable/class could
have its own description ($int->description), constructor with built
in validation ( $int = new Int32('123456') ) and casting/conversion (
$str = new String('12345'); $int32 = $str ).

For custom validation, maybe: $int = new Int32(); $int->validate =
function($value) { return $value < 100 && $value > 5; }; $int->value =
105; /* Throws error */

Parsers should be able to grab validations and description from the code.

This also will solve some peoples wishes for strict typing as:
function foo(String $arg1, Int32 $arg2, $arg3);

This is more overhead. But it is elective for those who wish to use
it. It won't burden existing application performance. And it doesn't
require learning another construct.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to