note 58351 added to language.operators.comparison

From: Date: Tue, 01 Nov 2005 15:42:16 +0000
Subject: note 58351 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-97931@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) # 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; } } ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58351 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58351&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58351&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97931) next »