|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-01-18 05:54 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2018-01-18 05:54 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 17:00:02 2026 UTC |
Description: ------------ When I compare two obejcts from two different but identially-looking classes then the comparison operators yield contradicting results. In the samle code below, there are two variables $a and $b which are not in ==, nor in === nor in <= nor in >= relationship. Moreover, the spaceship operator tells that $a>$b and $b>$a as well. Test script: --------------- error_reporting(E_ALL); class Objy_1 { public $v =1; } class Objy_2 { public $v =2; } $a = new Objy_1(); $b = new Objy_2(); var_dump($a < $b); // false var_dump($a > $b); // false var_dump($a == $b); // false var_dump($a === $b); // false var_dump($a <=> $b); // false var_dump($a <=> $b); // 1 which means $a > $b var_dump($b <=> $a); // 1 which means $b > $a Expected result: ---------------- I would expect non-contradicting results. In this concrete cases, I think $a == $b should be true, $a <=> $b and $b <=> $a should be 0. Moreover, I think it would be nice to get a warning if I want to compare objects from different classes.