I have a slew of object references, and I would like to be able to test for
reference identity as opposed to reference equivalence. Put another
way, I want to know if two references refer to the exact same object,
not whether they point to objects with the same content. As far as I
can tell, PHP only directly supports testing for equivalence.
Hmm. Some code:
class foobar
{
function foobar( $val=null )
{
$this->val = $val;
}
}
$foo = new foobar(1);
$bar =& $foo;
$baz = new foobar(1);
$identity = ($foo == $bar);
$equivalence = ($bar == $baz);
if ( $identity && !$equivalence )
echo "== tests object identity.\n";
else
if ( $identity && $equivalence )
echo "== tests object equivalence.\n";
PHP echo's the second statement. I need a way of producing the first
result. Any ideas? The only thing I can think of is a serious hack; modify
an object member in $foo and see if it changed in $bar. Is there a
proper way of doing that?