FAQ
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.

Search Discussions

  • Ferenc Kovacs at Sep 17, 2010 at 7:47 am

    On Fri, Sep 17, 2010 at 3:28 AM, Stanley Sufficool wrote:

    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
    http://wiki.php.net/rfc/splweaktypehintingwithautoboxing
    http://wiki.php.net/rfc/autoboxing<http://wiki.php.net/rfc/autoboxing?s[]=autoboxing>

    Tyrael

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedSep 17, '10 at 1:28a
activeSep 17, '10 at 7:47a
posts2
users2
websitephp.net

People

Translate

site design / logo © 2022 Grokbase