On Sun, Jul 13, 2014 at 02:35:43PM +0300, Zeev Suraski wrote: > Type juggling is an *inherent* feature of PHP. Paraphrasing what Rasmus > said several years ago(*), 'if you implement this [strong typing], please > don't call it PHP'. > > Again, luckily, what Andrea proposes isn't strong typing. It still > maintains the most important properties of type juggling - e.g. the > ability to work with strings coming in as input (GET/POST/etc.) without > having to worry about typing.
I think that you need to look at how and where this will be used. In (what I shall call) the outer parts of programs it may not be useful, but it will in the inner parts. Let me explain: The outer part of a program which will work with things like $_GET['age'] which might have values like: '10', 'ten', '10.5', '' or even be unset. Even assigning a value to '$age' and have PHP do type checking is not what you want. Type juggling is an important part of outer code. Input (form) variables are then type/... checked by validation tests, this will reject 'ten', '', unset and maybe '10.5'. I see this as a kind of firewall. The inner side only uses values that have been through the 'firewall', ie I know that $age will contain an integer. I can then do integer operations on it without further checking - indeed I do NOT want to have to do further checking since that just adds to the code size/complexity/ugliness. It is in this 'inner' code where I will want to use PHP type hinting as currently discussed. Although my values should have been though the firewall, I do make mistakes, etc, so the inner code either occasionally fails in an obscure way or assertions are done. Some means of having PHP help here would be very much appreciated. Which of the two below is clearer: function CanDrive($age) { if( !is_numeric($age)) throw new Error("\$age is not integer (CanDrive())"); return $age >= 17; } function CanDrive(int $age) { return $age >= 17; } The above is how I write programs. [I do realise that the 2 above are not exactly the same.] > (*) I couldn't find that email quickly enough so apologies if I'm not > completely accurate on this. -- Alain Williams Linux/GNU 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 #include <std_disclaimer.h> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php