PHP returns the reference type method. php returns the reference type. PHP returns the reference type method. php returns the reference type and returns the reference. when defining and calling the method, lt; php $ colorYellowGreen; functionnbsp; global $ color; return $ color ;} f PHP returns the reference type method, and 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:
The 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
Callback returns a reference. During definition and call, lt; php $ color = 'yellowgreen'; function nbsp; global $ color; return $ color;} f...