note 58351 modified in language.operators.comparison by danbrown

From: Date: Thu, 18 Jun 2009 14:14:15 +0000
Subject: note 58351 modified in language.operators.comparison by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157085@lists.php.net to get a copy of this message
Don't be deceived into thinking that === compares objects for identity, it does not. It does a recusrive comparison which fails if there are recusrive object references involved, and will report as identical two different object instances that happen to merely have the same value. You can see the stated problem at: http://bugs.php.net/bug.php?id=35053 My workaround is php::CompareObjects($a,$b) <?php # static class to hold methods to encapsulate php deficiencies in various versions class php { # in === on objects in php4 does a dumb recusrive check instead function CompareObject(&$a,&$b) { $value='Bah! Stupid==='; $key="bah".rand(0,1000); while(isset($a->$key)) $key.=rand(0,9); if (isset($b->$key)) return FALSE; $a->$key=$value; $result=($a->$key===$b->$key); unset($a->$key); return $result; } } ?> --was-- Don't be deceived into thinking that === compares objects for identity, it does not. It does a recusrive comparison which fails if there are recusrive object references involved, and will report as identical two different object instances that happen to merely have the same value. You can see the stated problem at: http://bugs.php.net/bug.php?id=35053 My workaround is php::CompareObjects($a,$b) # static class to hold methods to encapsulate php deficiencies in various versions class php { # in === on objects in php4 does a dumb recusrive check instead function CompareObject(&$a,&$b) { $value='Bah! Stupid==='; $key="bah".rand(0,1000); while(isset($a->$key)) $key.=rand(0,9); if (isset($b->$key)) return FALSE; $a->$key=$value; $result=($a->$key===$b->$key); unset($a->$key); return $result; } } http://php.net/manual/en/language.operators.comparison.php

« previous php.notes (#157085) next »