2009/7/1 Ilia Alshanetsky <i...@prohost.org>:
> There has been quite a bit of discussion on this list, IRC, developer
> meetings, etc... about introduction of type hinting to PHP. Most people
> appear to think that this would be a good idea, but there is a reason why it
> is not in PHP already. The main source of conflict appears to be that in
> some cases typical type hinting is just too strict for PHP's typeless nature
> (most people expect that "1" == 1, while int type hint would definitely
> reject string "1").  Personally, I disagree with that opinion, but I can
> understand people who raise that issue. At work we've been using PHP 5.2
> with type hinting for nearly 2 years now with great success, it makes code
> much easier to read and understand and the security benefit of type hinting
> is not to be under valued. In many cases type hinting can present a last
> line of defense against unexpected input for numeric fields, which are
> typically abused to do SQL injection.
>
> 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.


Brilliant stuff Ilia!

One thing I noticed in the patch is:

"+<ST_IN_SCRIPTING>("string"|"binary"|"unicode") {
+       return T_STRING_HINT;
+}
"

which makes sense if we keep for PHP6 but doesn't for 5_3 which afaik
doesn't have (unicode) casting yet :) I think that's nitpicking I
agree and I just want to make sure that this doesn't become a
documentation issue for people who'd think you can hint using unicode
or even see article saying you can hint with unicode.

Makes sense for PHP6 though but since you merged your patch from 5.2 I
figured I could ask :)

Apart from that this is awesome and am I glad that we are not trying
to cast automatically!

+1

-- 
Slan,
David

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

Reply via email to