Php references (that is, adding & symbol before variables, functions, and objects) in PHP mean that different names access the same variable content. The pointer in the C language 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. Variable reference PHP allows you to use two variables to point to the same content & lt ;? Php $ a & quot; ABC & quot; $ B & $ a; echo $ php reference (that is, add & symbol before variables, functions, and objects)
The reference in PHP means that different names access the same variable content.
The pointer in the C language 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.
Variable reference
PHP reference allows you to use two variables to point to the same content
Function address transfer call
I will not talk much about the address transfer call. the following code is provided directly.
"; Echo $ B; // output 101?>
Note that test (1); will cause an error.
Function Reference return
First look at the code
The following explains:
In this way, $ a = test (); is not actually returned by the function reference, which is no different from the normal function call. As for the reason:
This is a php rule. php requires that the function is referenced and returned in the $ a = & test (); method. As for what is reference return (in the PHP Manual, reference return is used when you want to use a function to find the variable on which the reference should be bound .) I haven't understood this sentence for a long time.
The example above is as follows:
$ A = test () method to call a function. it only assigns the value of the function to $, $ a does not affect $ B in the function and calls the function in the $ a = & test () method, the function is to direct the memory address of the $ B variable in return $ B to the same place as the memory address of the $ a variable, this is equivalent to the effect ($ a = & B ;) therefore, changing the value of $ a also changes the value of $ B. Therefore, after $ a = & test (); $ a = 5; is executed, the value of $ B is changed to 5.
Static variables are used to help you understand the reference and return functions. In fact, function reference and return are mostly used in objects.
12 Next page