Bug #75839 [NEW]: Undefined relation when objects compared
| From: | csongor at halmai dot hu | Date: | Thu, 18 Jan 2018 03:25:17 +0000 |
| Subject: | Bug #75839 [NEW]: Undefined relation when objects compared | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213600@lists.php.net to get a copy of this message | ||
From: csongor at halmai dot hu
Operating system:
PHP version: Irrelevant
Package: *General Issues
Bug Type: Bug
Bug description:Undefined relation when objects compared
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=75839&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75839&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75839&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75839&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75839&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75839&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75839&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75839&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75839&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75839&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75839&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75839&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75839&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75839&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75839&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75839&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75839&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75839&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75839&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75839&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75839&r=mysqlcfg