On Sun, Jan 06, 2008 at 12:51:20PM +0100, Kore Nordmann wrote: > > Am Sonntag, den 06.01.2008, 11:28 +0000 schrieb Alain Williams: > > PLEASE READ CAREFULLY > > > > You have NOT understood what type hinting is about. > > > > You are confusing the TYPE and the VALUE. > > > > What type hinting means is: > > > > * is the TYPE correct ? If so succeed. > > > > * can the VALUE be 100% converted to the desired TYPE (eg '5' to int) ? If > > so succeed. > > > > * fail > > > > Type HINTING is not type ENFORCEMENT. PHP type juggling is still allowed, > > so PDO returning results as strings > > is quite OK as long as what is defined to be numeric *really* has a VALUE > > that is a number. > > You may consider a virtual type like 'numeric' for it, but numeric > strings do NOT always behave like integers, so passing a string, when my > typehint says int, may cause lots of confusion - Stefan already said > this earlier. A simple example: > > $ php -r 'var_dump( ~"1", ~1 );' > string(1) "�" > int(-2) > > Or: > $ php -r 'var_dump( "1" ^ "2", 1 ^ 2 );' > string(1) "" > int(3)
Thank you for those examples. This is part of why part of the proposal of type hinting is to type juggle on entry to the function. Thus your code above, presumably within the type hinted function, would operate as the programmer intended. The more that I think about it the more that I understand that type hinting will be a boon to PHP and increase the quality of PHP applications. Remember: it is optional, if you don't like it - don't use it. -- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Chairman of UKUUG: http://www.ukuug.org/ #include <std_disclaimer.h> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php