On 27 June 2018 at 14:30, Wes <netmo....@gmail.com> wrote: > not some class, only same comparator function. e.g. this is ok, as __equals > is the same for both classes > trait X{ function __equals($o){ ... } } > class A{ use X; } > class B{ use X; } > assert((new A) == (new B)); >
What does "the same function" mean, though? The same text? The same entry in memory? In this example, the Trait will be copied into the class at compile time, so is not "the same function" in terms of internal representation. It may not even have the same code, since the magic contant __CLASS__ will be compiled to 'A' or 'B', never 'X'. Comparing by text doesn't seem that sensible; you could easily have two objects with "__compareTo($other) { return $this->value <=> $other-> value ; }" but that doesn't mean they should be comparable. The only meaningful constraint you could put on it is either "both objects are of the same class", or assert($other instance self) - i.e. compare against the same class or a sub-class. I think it's more straight-froward to always call the handler, and let the user decide which comparisons are computable. Regards, -- Rowan Collins [IMSoP]