I came across a code snippet which included $a = & $b;
but hadn\'t tested whether $b actually existed (if (isset($b))
). I wasn\'t sure how PHP
Explanation is as simple as this
If you assign, pass, or return an undefined variable by reference, it will get created.
(emphasis mine)
That's what you're doing; Assigning an undefined index by reference so it gets created.
Example #1 Using references with undefined variables
d);
var_dump(property_exists($c, 'd')); // bool(true)
?>
Example from PHP Manual
Then you have another question:
Meanwhile at the same time, $b[11] shows a value NULL and isset()=FALSE even though its referent (apparently) does exist (!)
That is also explained clearly on the manual
isset — Determine if a variable is set and is not NULL
isset() will return FALSE if testing a variable that has been set to NULL
Since it is NULL
, isset()
returns FALSE.