Excerpt from constructor

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.