0
function A($a) {
    xdebug_debug_zval('a');
}
$a = 1; # refcount->1
A($a); # refcount->2

The comment is what I think the refcount should be.

but output is:

a: (refcount=3, is_ref=0)=1

where is 1 addtional refcount come from?

shingo
  • 18,436
  • 5
  • 23
  • 42

1 Answers1

1

In the PHP documentation is described, that you have to pass the argument by reference. But passing arguments by reference has been removed in PHP 5.x. This issue leads us to the non function of debug_zval_dump. It 's impossible to get the right refcount with this function.

I guess it 's not recommended to use this function to count references. In my testing environment (Apache / PHP7.1) your example produces a refcount of 1. Seems to be a bit tricky.

Marcel
  • 4,854
  • 1
  • 14
  • 24