Reference in Constructor: php & nbsp; reference in & nbsp; constructor: reference in & nbsp; below is what I wrote in accordance with the manual & nbsp; however, the test results are different from those described in the manual ;? Php & nbsp; class & nbsp; Foo {function & nbsp; Foo ($ name) {reference in the glo constructor
At the beginning of learning php, I saw reference in the constructor in the php Manual. below is what I wrote in the manual, but the test results are different from what I said in the manual. error
Class Foo {
Function Foo ($ name ){
Global $ globalref;
$ Globalref [] = & $ this;
$ This-> setName ($ name );
$ This-> echoName ();
}
Function echoName ()
{
Echo'
', $ This-> name;
}
Function setName ($ name)
{
$ This-> name = $ name;
}
}
?>
$ Bar1 = new Foo ('set the name is php ');
$ Bar1-> echoName ();
$ Globalref [0]-> echoName ();
// Print_r ($ globalref );
// In the manual, if you reset a new name $ bar1 and $ globalref [0], the output is the same during the test.
$ Bar1-> setName ('set the name is Java ');
$ Bar1-> echoName ();
$ Globalref [0]-> echoName ();
?>
------ Solution --------------------
I don't know what your description comes from"
At least from the code perspective, it is based on php4. it is unknown whether it is like that in php4 without any environment.
------ Solution --------------------
Yes, the kernel of php5 is the same as that of php4. Otherwise, it is not php5 but php4.x.
Like all software systems, a major change in the version number indicates a major change.
Although there is not much difference from the php code perspective, the implementation method changes. It can be considered as two languages at all.
Therefore, the php4-based explanation cannot be used in php5.
Didn't you see an applicable version number on each function interpretation page in the manual?