2016-01-05 2:04 GMT+03:00 Andrea Faulds <a...@ajf.me>: > I agree that we could do something with interfaces. I would like to point > out that we actually already have an example of this, in the form of the > \ArrayAccess interface, which requires you to implement all the different > indexing operations at once. Unfortunately, though, \ArrayAccess doesn't > give us a precedent for dealing with the $this issue (in `$a + $b`, who > gets called, how do we handle differing types, etc?), but it's a start. >
Hi, Andrea and internals team! Interface is a good way to implement new functionality for classes, but operator overloading is language feature itself, so from my point of view, it will be better to put this functionality into the magic method. Personally, I don't like hundreds of __add, __mul, __etc methods, because this will be ugly and will require addition of new methods when new operators are included (eg __pow). I want to suggest to add only one single method: public function __operator(int $operatorKind, ...$operatorArgs); This method will be called for every operator and class can check the $operatorKind variable with simple check: if (Php\Operator::OP_DIVISION === $operatorKind) return $operatorArgs[0]->value / $operatorArgs[1]->value; New values for operator type enumeration can be added later into new versions of PHP easily.