The PHP address reference is different from the pointer in the C language. The pointer in the C language stores the address where the variable content is stored in the memory.
Let's talk nonsense. Let's look at the example first,
<? PHP
$ = " ABC " ;
$ B = & $ ;
Echo $ ; // Output here: ABC
Echo $ B ; // Output here: ABC
$ B = " EFG " ;
Echo $ ; // Here, the value of $ A is changed to EFG, so EFG is output.
Echo $ B ; // EFG output here
?>
As you can see in the above example, I will not talk about it any more. Let's take a look at the following example?
<? PHP
$ = " ABC " ;
$ B = & $ ;
Unset ( $ );
Echo $ B ; // Output here: ABC
?>
It turns out this way. When you unset a reference, you just disconnect the binding between the variable name and the variable content. This does not mean that the variable content is destroyed.
// Next is an episode
In PHP, the address pointing (similar to pointer) function is not implemented by the user, but is implemented by the Zend core. in PHP, the reference uses the principle of "Copy at write, unless a write operation occurs, the variables or objects pointing to the same address will not be copied.
In general, if the followingCode
<? PHP
$ = " ABC " ;
$ B = $ ;
?>
In fact, both $ A and $ B point to the same memory address, not $ A and $ B occupy different memory.
2: Add the following code on the basis of the above Code:
$ = " EFG " ;
Because the memory data pointed to by $ A and $ B needs to be re-written, the Zend core automatically determines that $ B will generate a $ A data copy, apply for a new memory for storage