//3 references are added, including when calling debug_zval_dump() return $count - 3;
} ?>
debug_zval_dump() is a confusing function, as explained in its documentation, as among other things, it adds a reference count when being called as there is a reference within the function. refcount() takes account of these extra references by subtracting them for the return value.
It's also even more confusing when dealing with variables that have been assigned by reference (=&), either on the right or left side of the assignment, so for that reason, the above function doesn't really work for those sorts of variables. I'd use it more on object instances.
However, even taking into account that passing a variable to a function adds one to the reference count; which should mean that calling refcount() adds one, and then calling debug_zval_dump() adds another, refcount() seems to have aquired another reference from somewhere; hence subtracting 3 instead of 2 in the return line. Not quite sure where that comes from.
I've only tested this on 5.3; due to the nature of debug_zval_dump(), the results may be completely different on other versions.
Youssef Omar (16-Dec-2009 04:27)
This is to show the affect of changing property of object A through another object B when you pass object A as a property of another object B.
<?php // data class to be passed to another class as an object class A{
public $info;
function __construct(){ $this->info = "eeee";
}
}
// B class to change the info in A obj class B_class{
public $A_obj;
function __construct($A_obj){ $this->A_obj = $A_obj;
}
public function change($newVal){ $this->A_obj->