If you have Xdebug installed, you can use Xdebug_debug_zval () to display "Zval" information. As follows:
Copy Code code as follows:
<?php
$str = "Jb51.net";
Xdebug_debug_zval (' str ');
Results:
Str:
(Refcount=1, is_ref=0),
String ' jb51.net ' (length=10)
The variable container is destroyed only when the "RefCount" becomes 0 o'clock. When you unset () a variable, the refcount of the desired "Zval" is reduced by 1, and the unset reference problem encountered a few days ago:
Copy Code code as follows:
<?php
$a = "AAA";
$b = & $a;
unset ($a);
Echo $b; This will still output AAA, print with Xdebug_debug_zval you'll know why.
Xdebug_debug_zval ("B");
Results:
B:
(Refcount=1, is_ref=0), String ' aaa ' (length=3)
Continue to refer to counter issues, which are different for array and object conformance types:
Copy Code code as follows:
<?php
$arr = Array (' A ' => ' aaa ', ' B ' => ' BBB ');
Xdebug_debug_zval (' arr ');
$arr [' aaa '] = $arr [' a '];
Xdebug_debug_zval (' arr ');
?>
Results:
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)
You can see that the original array element and the newly added array element are associated with the Zval variable container of the same "RefCount" 2. I'm just playing a role here.
Specifically on the PHP reference counter can refer to the manual: http://php.net/manual/zh/features.gc.refcounting-basics.php