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: