First, let's do a question:
$test = ' aaaaaa '; $ABC $test ; unset ($test); Echo $ABC;
The result I expected was that the hint was undefined, but the result was ' aaaaaa '.
Then I went to Baidu and found a very worth reading article: http://www.cnblogs.com/lonelyxmas/p/4205183.html
Here I will explain to my topic:
My understanding: At first only $test a variable point to aaaaaa, after $ABC reference to add the following line, unset just cut off the above line, and did not release the variable, so the final result output aaaaa.
Summarized as follows:
(1) When a constant is assigned to a variable, it allocates memory space for that variable.
(2) When a variable is assigned to a new variable in PHP, no memory space is allocated for the new variable immediately, but a reference to the memory space is added. A new variable is allocated a memory space when the original variable or new variable makes any changes.
(3) & when assigning a value, consider a variable to define an alias that adds a reference to the memory space. Changing one of these will affect the other references. When using unset (), only a reference to the variable memory space is broken, and the memory space is not freed.
Here's a B (because I can't read it now):
Each PHP variable exists in a variable container called "Zval". A Zval variable container that includes two bytes of extra information in addition to the type and value of the variable. The first is "Is_ref", which is a bool value that identifies whether the variable belongs to a reference collection (Referenceset). With this byte, the PHP engine can differentiate between normal and reference variables, and since PHP allows users to use the custom reference by using &, there is an internal reference counting mechanism in the Zval variable container to optimize memory usage. The second extra byte is "RefCount", which represents the number of variables (also known as symbols) that point to the Zval variable container. When the value of "RefCount" is 1 , the value of "Is_ref" is always FALSE
.
In-depth understanding of references and assignments in PHP