PHP returns the reference type. php returns the reference type.
Return reference, which cannot be omitted during definition and call.
This is a confusing concept. If it is not for some special reasons, we recommend that you do not use it.
He is easy to mix because of the changes in the Reference in PHP5, resulting in a large difference in the behavior of PHP4/PHP5.
For example:
Copy codeThe Code is as follows:
<? Php
$ Color = 'yellowgreen ';
Function & getRef (){
Global $ color;
Return $ color;
}
Function getCopy (){
Global $ color;
Return $ color;
}
$ ColorRef = & getRef ();
$ ColorRef = 'blue ';
// $ ColorCopy = getCopy ();
// $ ColorCopy = 'black ';
Var_dump ($ color );
Var_dump ($ colorRef );
// Var_dump ($ colorCopy );
Run the above Code and you will understand it. Use & getRef () to bind $ colorRef to $ color, that is to say, the variables $ colorRef and $ color point to the same value. When one value is changed, the other value also changes.
If $ color is an array, the above Code performs the same in any version of PHP4/5.
When $ color is an Object, the problem occurs.
In PHP4, getCopy still returns a Copied Object; & getRef () returns a reference.
PHP5 is a little different,
For the latest PHP5.2, the behavior is the same as that for PHP4. getCopy () returns the copy and & getRef () returns the reference.
However, some versions of PHP5 are slightly different here. For example, PHP5.1.6 indicates that both getCopy () and & getRef () are referenced.
Here, getCopy () and & getRef () are two global functions. If they are put into the class as the class's Member functions, it will be another scene ......
PS: Returning References does not improve the performance, but sometimes reduces the performance. Therefore, do not use this feature to "optimize" the program.
If you have any questions, you can find the answer most of the time in the manual:
Http://cn.php.net/manual/en/language.references.php