|
Posted by Oli Filth on 11/18/61 11:44
Jerry Stuckle said the following on 09/04/2006 06:14:
> Oli Filth wrote:
>> I have error level set to E_ALL | E_STRICT. The following code
>> executes fine:
>> <?php
>>
>> function getValueWithDefault(&$array, $key, $default = NULL)
>> {
>> return (isset($array[$key])) ? $array[$key] : $default;
>> }
>>
>> $var = array();
>> echo getValueWithDefault($var, "Roger", "Dodger") . "\n";
>>
>> ?>
>>
>> I see no reason why an error/warning should get thrown. isset()
>> simply looks for an element with the specified key name in the
>> associative array. In an empty array, the key doesn't exist, so
>> isset() returns false.
>>
>
> That's not what I said. I said if $var is EMPTY.
From the PHP manual for empty():
"The following things are considered to be empty:
...
array() (an empty array)
..."
> Take out the $var=array() line and see what you get.
So you mean "undefined"? Going back to the original purpose of this
function/macro, why would you ever want to call it on an undefined array?
But anyway, removing the $var = array() line does not result in any
error/warning. Because it's being passed by reference, PHP
automatically creates a variable $var in the global scope (because for
all it knows, this could be an output argument for the function).
--
Oli
Navigation:
[Reply to this message]
|