Today, I look at my brother. The article about PHP variable separation and reference, there is a problem did not understand, first put the parts out:
If you follow the above, I'll change the code slightly as follows:
So
The second line of code:
$var _dup and $var point to the same zval, RefCount is 2.
When the third line is executed:
PHP discovers that the zval to be manipulated is more than 1 refcount, then PHP executes separation, separates $var_dup, and $var and $var_ref do the change on write association. That is, refcount=2, is_ref=1;
At the time of the fourth line:
Because $var and $var_ref point to the is_ref=1 of the zval, there is no separation so that the $var_ref and $var values are "OK".
In my understanding, the program at the end, because $var_dup in the execution of the third line when it has been separated out, so its value should remain "laruence" unchanged, but, I run the program when found that it has become "OK", which makes me very difficult to understand, I want to know the answer to the great God to help me. Do not know whether I understand the wrong or other hidden, thank you!
In addition are two small chestnuts for the great God Reference:
Reply content:
Today, I look at my brother. The article about PHP variable separation and reference, there is a problem did not understand, first put the parts out:
If you follow the above, I'll change the code slightly as follows:
So
The second line of code:
$var _dup and $var point to the same zval, RefCount is 2.
When the third line is executed:
PHP discovers that the zval to be manipulated is more than 1 refcount, then PHP executes separation, separates $var_dup, and $var and $var_ref do the change on write association. That is, refcount=2, is_ref=1;
At the time of the fourth line:
Because $var and $var_ref point to the is_ref=1 of the zval, there is no separation so that the $var_ref and $var values are "OK".
In my understanding, the program at the end, because $var_dup in the execution of the third line when it has been separated out, so its value should remain "laruence" unchanged, but, I run the program when found that it has become "OK", which makes me very difficult to understand, I want to know the answer to the great God to help me. Do not know whether I understand the wrong or other hidden, thank you!
In addition are two small chestnuts for the great God Reference:
Copy On Write!!!!!!!!!!!!
写时复制!!!!!!!!!!!!
Does the third line of your code have a write operation? Why do you need to perform the separation!?
The third line of action is to increase the refcount to 3.