2009/7/6 Lupus Michaelis <[email protected]>:
> I'm happy PHP raises an error on foo(null) ;
> I'm in trouble when foo() doesn't.
>
> The actual question is : why PHP doesn't raise an error ?
This functionality (default values for passed-by-reference parameters)
was added in PHP5.
The problem is that you can't pass literals by reference (which makes sense):
function f(&$a) {}
f(45); // error
But default values must be literals (which also makes sense):
function f($a = $_POST) {} // error
So there's some serious impedance mismatch going on there to make both
features to work together. Just think of the default value as
"something I can overwrite", eg:
function f(&$a = 45) { $a = 99; }
So it doesn't really matter if it starts off as 45, 'Hello World' or
null... it's going to get thrown away at the end of the function's
lifetime, anyway.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php