The PHP documentation states:
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
AFAIK, PHP arrays are ordered hash-maps. So, why is it per se forbidden to use objects as keys, is there a reason for this limitation? Why is there no possibility to implement a hash function in a class in order to use it as a key?
On a related note, is there a PHP implementation of a hash-map which solves this issue?
Keys need to be immutable in order for them to work. If your objects are mutable, then they can’t be keys. That’s true in every language that implements them: Java, C#, etc.