Hello,

For what it's worth, a large +1 from me.

One concern I do have, however, is that the addition of scalar type hints will put more attention to the lack of method overloading. Right now methods can accept multiple values due to the type-lessness, and while it will remain a possibility, code with type-hints usually is a lot clearner. To demonstrate:

class Example {
   public function setValue (int $value) {}
   public function setValue (string $value) {}
}

While there are two obvious solutions for this (not using type-hinted parameters and using setIntValue/setStringValue) I think inclusion of a patch like this would be a good moment to overthink overloading like this.

Peter


"Ilia Alshanetsky" <i...@prohost.org> wrote in message news:fc14fafe-6785-4067-9b49-9fc14f159...@prohost.org...
I've taken a few hours this morning to port my 5.2 type hinting patch to 5.3. In recognition of a need for a more 'flexible' numeric type I've introduced (numeric) type hint that would allow bool/int/float data types as well as a string containing a numeric entity as identified by is_numeric_string(). For completion i've also added (scalar) data type that will allow any scalar data element.

The patch is available here: http://ia.gd/patch/type_hint_53.txt

It should be noted that this patch is fully compatible with opcode caches and and requires no changes on the part of an opcode cache such as APC to work.

My hope is that the latest changes will allow this to become a standard part of PHP.

Ilia Alshanetsky

P.S.

It should be noted that this is not the first idea for type hints, that credit goes to Hannes Magnusson who had posted a similar patch on the internals list back in 2006. Also, back in 2008 Felipe Pena wrote a type hinting patch for PHP that is available on wiki.php.net.


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

Reply via email to