李德康 李德康 - 29 days ago 9
PHP Question

why the refcount is 1 when i use debug_zval_dump() ? PHP

I can't comprehend the refcount that debug_zval_dump() print.

<?php
$str = "test function";
$sr1 = '';
$str1 = & $str;

debug_zval_dump($str);


The output of the above code: string(13) "test function" refcount(1)

when i delete the ampersand before the $str:

<?php
$str = "test function";
$sr1 = '';
$str1 = $str;

debug_zval_dump($str);


The output of the above code :string(13) "test function" refcount(3)

what has happened ? The first refcount is "1".But, i think it also referenced three times.

Answer

Because a copy of $str is being made, when the function is called.

Comments