Are objects equal or not? PHP defines only instance equality using ===
operator. Then there is comparision by value ==
which compares by object values, but user-land code cannot modify how they are compared.
This is why universal equals()
method exists in Java. PHP is missing anything like that.
This is why I have implemented global equals()
function provides logic equality of objects. Which objects are equal and which not can be modified by several things - see bellow.
composer require grifart/equalable-utils
There are several ways of implementhing logic equality.
Hashable is PHP clone of Java equals()
and hashCode()
method. If you like to use implementing objects in collection this would make the most sense.
This library supports \Comparable
interface and tries to compare objects.
This methods must behave the same as Java equals()
method.