Home >Backend Development >PHP Tutorial >About PHP's debug_zval_dump and xdebug_debug_zval
Dear masters, I would like to ask why the refcount obtained by debug_zval_dump and xdebug_debug_zval are different?
For example:
<code> $var = "laruence"; $var_1 = &$var; $var_2 = &$var; $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; //debug_zval_dump得到的refcount等于1 //xdebug_debug_zval得到的refcount等于3 </code>
Although I read online that refcount indicates how many variable names point to this zval container, I still don’t know why the results are inconsistent. I haven't found a detailed introduction to this function. . .
But I have summarized the following rules:
When there is a variable reference, the result obtained by using xdebug_debug_zval is: is_ref=1;refcount=the number of variable references (counting the variable itself)
For example
<code> $var = "laruence"; //第1次 $var_1 = &$var; //第2次 $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; </code>
So, from xdebug_debug_zval we can get is_red=1;refcount=2;
When the variable is not referenced, the result obtained by using xdebug_debug_zval is: is_ref=0;refcount=the number of copies of the variable (counting the variable itself)
For example
<code> $var = "laruence"; //第1次 $var1 = $var; //第2次 $var2 = $var; //第3次 $var3 = $var; //第4次 $var4 = $var; //第5次 </code>
So, from xdebug_debug_zval we can get is_red=0;refcount=5;
When there is a variable reference, the result obtained by using debug_zval_dump is: refcount=1 (always=1)
For example
<code> $var = "laruence"; $var_1 = &$var; $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; </code>
So, from debug_zval_dump we can get: refcount=1;
When the variable is not referenced, the result obtained by using debug_zval_dump is: refcount = the number of copies of the variable (counting the variable itself) + 1
For example
<code> $var = "laruence"; //第1次 $var1 = $var; //第2次 $var2 = $var; //第3次 $var3 = $var; //第4次 $var4 = $var; //第5次 </code>
So, from xdebug_debug_zval we can get is_red=0;refcount=6;
Dear masters, I would like to ask why the refcount obtained by debug_zval_dump and xdebug_debug_zval are different?
For example:
<code> $var = "laruence"; $var_1 = &$var; $var_2 = &$var; $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; //debug_zval_dump得到的refcount等于1 //xdebug_debug_zval得到的refcount等于3 </code>
Although I read online that refcount indicates how many variable names point to this zval container, I still don’t know why the results are inconsistent. I haven't found a detailed introduction to this function. . .
But I have summarized the following rules:
When there is a variable reference, the result obtained by using xdebug_debug_zval is: is_ref=1;refcount=the number of variable references (counting the variable itself)
For example
<code> $var = "laruence"; //第1次 $var_1 = &$var; //第2次 $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; </code>
So, from xdebug_debug_zval we can get is_red=1;refcount=2;
When the variable is not referenced, the result obtained by using xdebug_debug_zval is: is_ref=0;refcount=the number of copies of the variable (counting the variable itself)
For example
<code> $var = "laruence"; //第1次 $var1 = $var; //第2次 $var2 = $var; //第3次 $var3 = $var; //第4次 $var4 = $var; //第5次 </code>
So, from xdebug_debug_zval we can get is_red=0;refcount=5;
When there is a variable reference, the result obtained by using debug_zval_dump is: refcount=1 (always=1)
For example
<code> $var = "laruence"; $var_1 = &$var; $var1 = $var; $var2 = $var; $var3 = $var; $var4 = $var; </code>
So, from debug_zval_dump we can get: refcount=1;
When the variable is not referenced, the result obtained by using debug_zval_dump is: refcount = the number of copies of the variable (counting the variable itself) + 1
For example
<code> $var = "laruence"; //第1次 $var1 = $var; //第2次 $var2 = $var; //第3次 $var3 = $var; //第4次 $var4 = $var; //第5次 </code>
So, from xdebug_debug_zval we can get is_red=0;refcount=6;