The PHP variable has been found to have REFCOUNT__GC (number of references) and IS_REF__GC (whether referenced) in the Zval struct
For example:
<?php
$a = "Hello World";
?>
At this point PHP will create a zval container because this variable is not a reference so the is_ref__gc of this container is false and REFCOUNT__GC is 1
And look at the code below.
<?php
$a = "Hello World";
$b = $a;
?>
Here because $b is not quoted $ A so here the Zval container is_ref__gc or false refcount__gc for 2 here we're sure to have doubts.
Why not quote REFCOUNT__GC and 2? This is due to PHP's write-time replication mechanism
<?php
$a = "Hello world";//The REFCOUNT__GC at this time is 1 is_ref__gc for 0
$b = $a;//The REFCOUNT__GC at this time is 2 is_ref__gc for 0
$a = "change";//The REFCOUNT__GC at this time is 1 is_ref__gc to 0
?>
When $ A is assigned to $b $a REFCOUNT__GC plus 1 is $ A $b is pointing to the same memory when $ A changes refcount__gc back to 1 because a memory block has been recreated to hold the new value, which is the copy-on-write mechanism
<?php
$a = "Hello world";//The REFCOUNT__GC at this time is 1 is_ref__gc for 0
$b =& $a;//refcount__gc at this time is 2 is_ref__gc for 1
$a = "change";//The REFCOUNT__GC at this time is 2 is_ref__gc to 1
?>
When a variable is shown to refer to another variable, refcount__gc is_ref__gc will add one to see how PHP determines when the variable is copied
If IS_REF__GC has a value (not 0) or refcount__gc <2 is 1, you can modify the variable so that it returns the entity of the variable directly instead of copying its value.
If IS_REF__GC is 2, changing the value of a variable will change the value of 2 variables because all 2 of these variables are a block of memory pointing to each other.
If refcount__gc <2 and is_ref__gc = 0 Modifies a value only changes the value of 1 variables and of course there's only one variable.
Rookie, write not good not to spray. Just to be able to turn over the nostalgia
PHP Reference and write-time replication