From: dmitrijsl at swh-t dot lv
Operating system: Windows 2000
PHP version: 5.0.0b1 (beta1)
PHP Bug Type: Feature/Change Request
Bug description: Custom comparison of objects: __equals method
Description:
------------
If a class defines a __equals($other) function, invoke that function on
object comparison. Example:
==========================
class MyClass {
public function __construct($value) {
$this->value = $value;
}
/**
* This function should be invoked on object
* comparison with == or != operators.
*/
public function __equals($other) {
if ($other instanceof MyClass) {
return ((int)$this->value
== (int)$other->value);
} else {
return false;
}
}
private $value;
}
$a = new MyClass(3.14);
$b = new MyClass(3.13);
if ($a == $b) {
echo '$a equals $b';
}
==========================
The comparison of $a and $b should result in the invokation of __equals
function of MyClass. The same should apply to the != (not equals)
operator.
--
Edit bug report at http://bugs.php.net/?id=25772&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25772&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25772&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25772&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25772&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25772&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25772&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25772&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25772&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25772&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25772&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25772&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25772&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25772&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25772&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25772&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25772&r=float