PHP variable separation and reference

Source: Internet
Author: User
Today, I have read the article about separation and reference of PHP variables. I have not figured out a problem. I will post some of them first: If I follow the above statement, I will slightly modify the code as follows: {code ...} the second line of the code: $ var_dup and $ var point to the same zval, refco...

Today, I am reading the article about separation and reference of PHP variables. I have not figured out a problem. I will post some of them first:

As mentioned above, I will slightly modify the code as follows:


  

So

The second line of the code:
$ Var_dup and $ var point to the same zval, and refcount is 2.

When the third line is executed:
If PHP finds that the refcount of zval to be operated is greater than 1, PHP will execute Separation, separate $ var_dup, and associate $ var and $ var_ref with change on write. That is, refcount = 2, is_ref = 1;

In the fourth row:
Because $ var and $ var_ref point to the zval is_ref = 1; therefore, they are not separated, so that the values of $ var_ref and $ var are "OK ".

In my understanding, at the end of the program, because $ var_dup has been separated when executing the third row, its value should remain "laruence",, when I run the program, I find that it has also become "OK", which makes me very puzzled. I don't know if I have understood it wrong or I have other feelings. thank you!

We also attached two small chestnuts for your reference:


  

  

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.