Comparing objects on PHP5

From: Date: Sun, 09 May 2004 07:43:53 +0000
Subject: Comparing objects on PHP5
Groups: php.internals 
Request: Send a blank email to internals+get-9741@lists.php.net to get a copy of this message
Hi, I think objects comparison in PHP5 has problems. Here is small sample code, <?php class Foo { var $v = 1; } class Boo { var $v = 1; } $a = new Foo; $b = new Foo; $c = new Boo; $d = new Foo; $d->v = 2; $e = $a; // value comparison echo $a == $b ? "same," : "not same,"; echo $a == $c ? "same," : "not same,"; echo $a == $d ? "same," : "not same,"; echo $a == $e ? "same" : "not same"; echo "\n"; // value and type comparison echo $a === $b ? "same," : "not same,"; echo $a === $c ? "same," : "not same,"; echo $a === $d ? "same," : "not same,"; echo $a === $e ? "same" : "not same"; ?> The output from PHP4 and PHP5(ze1_compat on/off) is, PHP 4.3.6 : same,not same,not same,same same,not same,not same,same PHP 5.0.0RC2 zend.ze1_compatibility_mode=off : same,not same,not same,same (Notice: Object of class [Foo|Boo] could not be converted to integer) not same,not same,not same,same PHP 5.0.0RC2 zend.ze1_compatibility_mode=on : same,same,not same,same not same,not same,not same,not same The problem and question are, 1. the different class is recognised as same in PHP5 (ze1_compat=on). 2. the same object is recognised as different in PHP5 (ze1_compat=on). 3. Why integer casting of object was implicitly applied in PHP5 (ze1_compat=off) ? -- Rui Hirokawa <rui_hirokawa@ybb.ne.jp>

« previous php.internals (#9741) next »