PHP variable Issues
$b = ' AAA ';
$a =& $b;
$b = ' DDD ';
Unset ($b);
echo $a;
Output DDD at this time;
Question: $a =& $b; This is to assign the memory address of variable B to $ A, and change the value of B to a.
Unset ($b) destroyed the variable B;echo $a why is it possible to output a value?
------Solution--------------------
$b = ' DDD ' has changed the memory address of the $b.
------Solution--------------------
You first $a=& $b, in fact, a $ A stealth to $b address, you unset ($b) only after the $b and the value of the mapping relationship is canceled, and does not affect a $ A
I wonder if the description is clear ... Cold,, long time not to do PHP long not to come up to irrigation, expression ability has become worse
------Solution--------------------
PHP Code
From the C point of view, the structure of the $a this variable contains a pointer to the $b variable, that is, $ A to save the $b variable address,//unset ($b), the PHP engine does not really release the content of this address, the time of the release of the variable should be determined by the engine's memory recovery mechanism $b = ' AAA '; $a = & $b; $c = & $b;//Add a reference here, perhaps the PHP engine also takes this into account, so do not immediately release the variable//when memory fragmentation is too much, it will be recycled and reused, to avoid repeated application of small block memory, reduce efficiency $b = ' CCC '; unset ($b); $c = ' ddd '; unset ($c); Echo ' $a '. $a;//output ddd//above only conjecture, for reference only