function value(&$param){}
value($var['key']);
echo array_key_exists("key", $var)? "true" : "false"; //true
After running this code, $var['key'] ends up existing despite never being explicitly set. This means empty($var)
will no longer return true
, which kind of bothers me.
Is this behavior intended? I couldn't find documentation on that.
A simpler code that gives the same result :
$foo = &$bar['key'];
$echo array_key_exists('key', $bar)? "true" : "false";
To pass by reference, there must be a reference to pass. To have a reference to pass, the variable must be created. So having the variable created in your code above would be expected.
This would be similar to the situation with the built-in
exec( $cmd, $out)
where $out will exist even if $cmd produces no ouput.In your code you might try
empty($var['key']
.