Re: RFC Operator Overloading in Userspace
| From: | Johannes Schlüter | Date: | Mon, 04 Jan 2016 19:39:04 +0000 |
| Subject: | Re: RFC Operator Overloading in Userspace | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-89999@lists.php.net to get a copy of this message | ||
On Sat, 2016-01-02 at 18:14 -0800, Sara Golemon wrote:
> https://wiki.php.net/rfc/operator-overloading
Back in the days when I created the first implementation of operator
overloading in the engine[1] I didn't see it fit for the language.
Meanwhile we have more type hints and stuff making it a bit less magic.
I still don't think this approach is really good. for instance we loose
associativity; taking the Complex example:
<?php
$a = new Complex(1, 2);
$b = 3;
echo $a + $b; // works
echo $b + $a; // will error out
?>
Of course this can easily be fixed by looking at the order, at least in
this simple case. In a more complex example where a function might
return an integer, double or complex number this becomes more
complicated.
For this to work we'd need non-member functions to do this and we need
function overloading ...
I believe we'll only get a half-baked solution and I prefer the current
state over half-baked.
johannes
[1] http://news.php.net/php.internals/14558