# Annotations Alternative?

- Thread: https://externals.io/message/49742
- Original archive: https://news-web.php.net/php.internals/49742
- Started by Stanley Sufficool on 2010-09-17T01:28:56+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49742 — Stanley Sufficool — 2010-09-17T01:28:56+00:00

URL: https://externals.io/message/49742#49742

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.

---

## #49744 — Ferenc Kovacs — 2010-09-17T07:47:37+00:00

URL: https://externals.io/message/49742#49744 · In reply to: #49742

On Fri, Sep 17, 2010 at 3:28 AM, Stanley Sufficool <ssufficool@gmail.com>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.
>
> --
> 
> 
>
>
http://wiki.php.net/rfc/splweaktypehintingwithautoboxing
http://wiki.php.net/rfc/autoboxing<http://wiki.php.net/rfc/autoboxing?s[]=autoboxing>

Tyrael
