Bug #75839 [Opn->Nab]: Undefined relation when objects compared
| From: | requinix@php.net | Date: | Thu, 18 Jan 2018 05:54:42 +0000 |
| Subject: | Bug #75839 [Opn->Nab]: Undefined relation when objects compared | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213601@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75839&edit=1
ID: 75839
Updated by: requinix@php.net
Reported by: csongor at halmai dot hu
Summary: Undefined relation when objects compared
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Objects of different classes are not comparable.
http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types
Previous Comments:
------------------------------------------------------------------------
[2018-01-18 03:25:14] csongor at halmai dot hu
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 this bug report at https://bugs.php.net/bug.php?id=75839&edit=1