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

> 
> On 14 Jul 2014, at 15:03, Rowan Collins <rowan.coll...@gmail.com> wrote:
> 
>> Looking at the current table in the RFC, I'm not clear why NULL should pass 
>> as any value, but not array. Could it not behave the same as the existing 
>> type hints, i.e. accepted only if declared as a default?
>> 
>> function foo(array $bar) { } foo(null); // ERROR
>> function foo(array $bar=null) { } foo(null); // OK, $bar == NULL
>> function foo(int $bar) { } foo(null); // ERROR
>> function foo(int $bar=null) { } foo(null); // OK, $bar == NULL
> 
> I’m thinking this as well. I wonder if perhaps it should be casted by 
> default, but if you make it explicitly nullable, it won’t cast if NULL is 
> passed.

This has been done now, as it was what I wanted to do and Anthony’s original 
intention. It works like this:

    function foo(int $a) { var_dump($a); }
    function bar(int $a = NULL) { var_dump($a); }

    foo(NULL); // int(0)
    bar(NULL); // NULL

--
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