On Sat, May 22, 2010 at 06:30:15PM +0200, Josh Davis wrote: > On 22 May 2010 17:04, Zeev Suraski <z...@zend.com> wrote: > > As one of the key people who designed PHP's type system I consider strict > > type checks completely alien to and counterintuitive in PHP and am therefore > > pushing to implement 'weak' typing instead, in a way that's consistent and > > familiar to users. > > I would normally refrain from posting on the dev list but as a "user" > I feel the need to make sure that my position isn't misrepresented, so > here it is.
OK, another 'user' input. I'll start by taking a step back and asking *why* type hinting/checking seems desirable to me: 1) If I write some low level function I don't want to have to check the types of my arguments because: a) it makes my code bigger/slower/more-complex b) error reporting may be hard (in really generic code) c) input should have been validated looong before it is passed to my function d) I expect my users (who are programmers) to have read my documentation e) I expect type errors to be rare (a reiteration of (a) above) 2) If there is a type error it could break my code, type checking will protect me without the penalty of me checking. 3) Type hinting may allow the PHP engine to run faster; a) eg: we know that $count is int - so no need to forever check. b) eg: juggle $count to int when the function is called, then it does not need to be juggled at every point that it is used. I like the idea of strict & weak checking; they do 2 different things: * strict checking * Checking in the manner of === -- no juggling at all * prob used internally within a package, eg for 'private' methods * used where there is certainty of the type that is being passed * weak checking * Ensure that the *value* is what I expect * Type juggle iff this can be done 100% cleanly, so allow: * int as float * float as int if it will pass a range check * "12" as int, but not "12a" or "" * Juggling is to prevent my user having to use casts * Juggling then means that I can call functions that specify strict checking * The user has passed the correct *value*, it is not just the correct type, eg: $age is "12", a string, because it came from a validated form or from a database. I view strict checking as 'rigid' use within related functions. I view weak checking as an 'input filter' to my type checked code. I note that someone said that this would just result in people casting values without proper checking. This may be true, but you can't protect those who won't use the tools that you give them. Maybe there ought to be strong/weak casting... eg (+int). Lukas' proposal does not cover everything, eg the types of elements of an array are not dealed with. However I believe that the checking of scalars would be a great improvement. Regards -- 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 Past 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