note 74342 deleted from language.references.spot by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: Steve Clay 

----

BenBE's function is broken for testing objects. Here's a variation on it just for testing objects:

<?php
function same_obj(&$var1, &$var2) {
    if ($var1 !== $var2) {
        return false;
    }
    $same = false;
    $key = uniqid("same_obj_", true);
    $var1->$key = $key;
    if (isset($var2->$key) && $var2->$key == $key) {
        $same = true;
    }
    unset($var1->$key);
    return $same;
}

// PHP4 references are risilient as array members
$f1 =& new Foo;
$f2 = array(&$f1);
$f3 = $f2;
echo (int)same_obj($f1, $f3[0]); // 1!
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.