We can know that in PHP, the variable starts with a $ symbol, and then the name of the variable. Variables can be referenced to one content, and PHP references allow you to point to the same content with two variables.
<?php $a = 1; $b = $a; echo '$a ='.$a.'; '.'$b = '.$b."\n". $b = 2; echo '$a ='.$a.'; '.'$b = '.$b."\n".
Next, the example code is as follows:
$ A assigns $ b, copy one copy The variable on the right will generate a memory space, and the result may be the same content in memory. At this time, the variable A and the variable B also point to the same content "1", so the output result is "1". When the "$ 2" statement is executed, the variable B is changed to the content "2", the original variable A has no effect, but the point of variable B has changed, so the output result variable A has no change, the variable B is "2".
<?php $c = 1; $d = &$c; echo '$c ='.$c.'; '.'$d = '.$d."\n". $d = 2; echo '$c ='.$c.'; '.'$d = '.$d."\n".$ c = 1; $ b = 1; $ c = 2; $ b = 2;
$ c will assign the value to $ D, add “&” symbols, symbol “&” to reference. With reference, the PHP engine will not copy a variable, in fact, point the pointer to the address of $ A in memory, and this pointer is saved. Modifications to any of them will affect other variables, and delete one of these variables, others will be active.
Name; Echo $ C-> Name; $ b-> name = “bob”; Echo $ C-> Name; $ b = null; $ c = null; // This time the destructor is the destructor? >
JAM JAM BOB
Name; ECHO $ C-> Name; $ b-> name = "bob"; Echo $ C-> Name; $ B = NULL; // At this time, the destructor is the destructor?>
JAM JAM BOBFrom the case of the case, it can be seen that $ b and $ c can call the properties in the function A, and some of them can make changes to the content content, when $ b and $ c are empty. However, there is no variable in the reference object, and the destructor is called. In case 2, add the & symbol when the variable is assigned, meaning that a $ C equivalent to $ B is copied, both is equal. When one of them is empty, the other party will also be empty, and the destructor is called.