Home > Backend Development > PHP Tutorial > About PHP's debug_zval_dump and xdebug_debug_zval

About PHP's debug_zval_dump and xdebug_debug_zval

WBOY
Release: 2016-10-23 00:12:55
Original
1018 people have browsed it

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>
Copy after login
Copy after login

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:


About xdebug_debug_zval:

  • 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

So, from xdebug_debug_zval we can get is_red=0;refcount=5;

About debug_zval_dump:

  • 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

So, from xdebug_debug_zval we can get is_red=0;refcount=6;

Reply content:

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>
Copy after login
Copy after login

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:


About xdebug_debug_zval:

  • 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

So, from xdebug_debug_zval we can get is_red=0;refcount=5;

About debug_zval_dump:

  • 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

So, from xdebug_debug_zval we can get is_red=0;refcount=6;

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template