Hi!

> In other words, $a == $b must not work if $a->__equals and $b->__equals are
> two different functions
> 
> So effectively it means we only call __equals if both sides are instances
> of the same class?

We can just define that == calls __equals on the left. That's, for
example, what Python does. This would produce a weird consequence of $a
== $b and $b == $a not being the same, but that's what you get for
overloading operators. That's why overloading operators is not always
the best idea, because of disconnect between perceived semantics (math
equality operator, which is symmetric, reflexive and transitive) and
actual semantic (which is not guaranteed to have any of the math
equality properties).

In any case, "the same class" would be too restrictive, as there's
inheritance, so we should support LSP. But then again, if $a and $b are
in different places on inheritance hierarchy, we can can non-symmetric
operator. This is kinda deep problem that is not really working well in
most Java code, for example. See:
https://www.artima.com/pins1ed/object-equality.html (for reference,
Martin Odersky is the guy who did Java generics, and designed Scala, so
he knows a quite bit about OO things :)

-- 
Stas Malyshev
smalys...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to