ObjectEquality
in
An object implementing this interface can determine if it equals any other value.
Strict comparison ($a === $b
) does not work on different instances of objects that represent the same value.
Regular comparison ($a == $b
) is possible, but you need to remember to use it on object comparison, but not on
other value types which is confusing. By implementing this interface on the objects that require comparison you can
use $a->equals($b)
and you have all the control.
Table of Contents
Methods
- equals() : bool
- Determines if object should be considered equal to other value.
Methods
equals()
Determines if object should be considered equal to other value.
public
equals(mixed $otherValue) : bool
In most cases the method evaluates to true if the other value has the same type and internal value(s) with an implementation like the following.
public function equals(mixed $other): bool
{
if ($other instanceof self) {
return $other->value === $this->value;
}
return false;
}
Parameters
- $otherValue : mixed
-
The other value with which to compare
Tags
Return values
bool —True if this object should be considered equal to other value