Dan Ackroyd wrote on 29/01/2016 13:56:
On 29 January 2016 at 10:46, Rowan Collins <rowan.coll...@gmail.com> wrote:
You appear to be suggesting that "get_class()" should behave differently
than "get_class(null)".
I don't know if internal parameter handling (ZPP) works like userland
parameters
Regardless of how internals works, it's a thing in userland PHP.
function foo($bar = null)
{
echo "number of args is: ".func_num_args(). "\n";
}
foo();
foo(null);
// Output is:
// number of args is: 0
// number of args is: 1
It's a useful thing to do when you want to distinguish between null
being passed, and the default value being used. Just like in this
case. The same is possible for internal functions.
OK, so it's possible, but it's not something I've seen done very often,
and in my opinion it would be a really confusing thing to do.
"Ah, an optional parameter, what does it default to?" "Nothing" "You
mean null?" "No, null has a separate meaning" "Separate from what?"
"Nothing" etc...
It's worryingly reminiscent of the endless debates about isset() and
distinguishing an non-existent variable from one which has been
explicitly set to null - you're inventing an extra kind of "very null".
Presumably you'd get to this point by saying "if $bar is an int, do
this; if $bar is null, do this; oh, I need a third case, let's do some
magic with func_num_args()"; so what happens when you need a fourth case?
Even worse, in this case, you're doing the opposite of what many
functions do - rather than saying "this parameter used to be optional,
but now you have to be specific even if you pass null", you're saying
"this parameter is still optional, but if you pass its default value in
you'll get a notice/warning".
I understand the intention, but I think this approach would just lead to
confusion.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php