If you have installed xdebug, you can use xdebug_debug_zval () to display "zval" information. As follows:
Copy codeThe Code is as follows: <? Php
$ Str = "jb51.net ";
Xdebug_debug_zval ('str ');
Result:
Str:
(Refcount = 1, is_ref = 0 ),
String 'jb51. net' (length = 10)
The variable container is destroyed only when "refcount" is changed to 0. when you unset () a variable, the refcount in the desired "zval" will be reduced by 1. Let's talk about the unset reference problem encountered a few days ago:
Copy codeThe Code is as follows: <? Php
$ A = "aaa ";
$ B = & $;
Unset ($ );
// Echo $ B; // aaa will still be output here. Print it with xdebug_debug_zval and you will know why.
Xdebug_debug_zval ("B ");
Result:
B:
(Refcount = 1, is_ref = 0), string 'aaa' (length = 3)
Continue to talk about the reference counter problem. The matching types of array and object are different:
Copy codeThe Code is as follows: <? Php
$ Arr = array ('A' => 'aaa', 'B' => "bbb ");
Xdebug_debug_zval ('arr ');
$ Arr ['aaa'] = $ arr ['a'];
Xdebug_debug_zval ('arr ');
?>
Result:
Arr:
(Refcount = 1, is_ref = 0 ),
Array
'A' => (refcount = 1, is_ref = 0), string 'aaa' (length = 3)
'B' => (refcount = 1, is_ref = 0), string 'bbb '(length = 3)
Arr:
(Refcount = 1, is_ref = 0 ),
Array
'A' => (refcount = 2, is_ref = 0), string 'aaa' (length = 3)
'B' => (refcount = 1, is_ref = 0), string 'bbb '(length = 3)
'Aaa' => (refcount = 2, is_ref = 0), string 'aaa' (length = 3)
We can see that the original array elements and newly added array elements are associated with the zval variable container of the same "refcount" 2. Here I am only playing a role in attracting others.
For details about the PHP reference counter can refer to the Manual: http://php.net/manual/zh/features.gc.refcounting-basics.php