Re: Type hinting

From: Date: Sun, 23 May 2010 14:22:21 +0000
Subject: Re: Type hinting
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-48413@lists.php.net to get a copy of this message
At 16:10 23/05/2010, Davey Shafik wrote:
We also already have a precedent for type-caring functions in the ctype_* functions: $ php -r 'var_dump(ctype_digit(123), ctype_digit((string) 123));' bool(false) bool(true)
There's a very specific reason for this behavior - ctype treats numeric values as ASCII and checks if they're in the right range. So, for instance, ctype_digit(48) would return true. Talk about a high WTF factor... Personally I think that's probably a poor decision, and I either way I wouldn't qualify it as precedent. Sure, there are functions that don't auto-convert and behave differently depending on the type that's passed to them - but they're very much the exception to the rule. Zeev

« previous php.internals (#48413) next »