2012/3/12 Lazare Inepologlou <linep...@gmail.com>
>
> function set_check_box_state( bool state = false ) { ... }
> set_check_box_state( null );  // null will be converted to false here...
>
> Therefore, this cannot work, unless the default value becomes null, which
> is against the requirements. What I suggest is something like this:
>
> function set_check_box_state( bool? state = false ) { ... }
> set_check_box_state( null );  // works fine
>
> In my opinion this is much clearer, as it separates the notions of the
> type
> and that of the default value.
>
>
> Lazare INEPOLOGLOU
> Ingénieur Logiciel

Hi Lazare,

I'd like to keep the accptance of null as it is for classes and arrays.
Here's an example I wrote earlier:

function foo(array $d = array()) { var_dump($d); }
foo(null); // This fails with the message: Argument 1 passed to foo()
must be an array, null given

As this code fails I'd not expect to change this behavior for the new
feature we're discussing here.

function foo(int $d = 20) { var_dump($d); }
foo(null); // This should then also simply fail. Don't care about
what's the default-value or defined type.

function foo(int $d = null) { var_dump($d); }
foo(null); // And this should pass it through, providing the
NULL-value in the function.

function foo(int $d = 20) { var_dump($d); }
foo( (int)null ); // This can provide 0 as the programmer forcing it
to be an integer before putting it into this function-call.

I would personally not like to give the user the option to set a
null-value if it's not the default.
But .. I don't wanna screw up your idea.

Bye
Simon

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

Reply via email to