On 18 Jul 2014, at 14:09, Andrea Faulds <a...@ajf.me> wrote:

> On 18 Jul 2014, at 06:02, Theodore Brown <theodor...@outlook.com> wrote:
> 
>> Another concern I have is in regard to the future. I'm looking forward to 
>> the 
>> possibility of specifying nullable types in a future version of PHP (see 
>> Levi Morrison's "Declaring Nullable Types" RFC: 
>> http://wiki.php.net/rfc/nullable_typehints). If the 
>> nullable types RFC is accepted, it would be highly disconcerting if scalar 
>> type 
>> annotations allowed null values regardless of whether a nullable marker is 
>> specified.
> 
> The current proposed behaviour could be changed. At the moment, if a scalar 
> type hint is nullable, then it won’t cast NULL if it’s passed that value, but 
> if it’s not nullable, then it will cast it.
> 
> Considering how this tends to only allow lossless casts, though, it might be 
> worth reconsidering this and just disallowing NULL altogether. It’s worth 
> pointing out that NULL is usually an error value, and you might get it from 
> using an uninitialised variable or calling an internal function with bad 
> parameters.

I’ve updated the RFC and patch to make int, string and double nullability work 
like the other types (bool already did). If the default value isn’t NULL, NULL 
isn’t accepted and you’ll get E_RECOVERABLE_ERROR. If the default value is 
NULL, NULL is accepted and will not be casted.

This will likely lead to less bugs as NULL is a common error value, and it also 
makes the scalar type hints more consistent with the others.
--
Andrea Faulds
http://ajf.me/





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

Reply via email to