Object identity check
Posted: Mon Sep 18, 2006 2:26 pm
How do you test whether two variable are referencing the same object? I have two instances of $db, and I'm not sure whether they reference the same object... how can I check?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
class foobar {
private $xyz;
public function __construct($xyz) {
$this->xyz = $xyz;
}
}
$f1 = new foobar(1);
$f2 = $f1;
$f3 = clone $f1;
$f4 = new foobar(4);
echo '$f1===$f2: ', $f1===$f2 ? 'true':'false', "<br />\n";
echo '$f1===$f3: ', $f1===$f3 ? 'true':'false', "<br />\n";
echo '$f1===$f4: ', $f1===$f4 ? 'true':'false', "<br />\n";
?>