On Sat, 2020-03-28 at 17:05 +0100, Christoph M. Becker wrote:
> On 28.03.2020 at 15:57, Johannes Schlüter wrote:
>
> > On March 28, 2020 1:25:11 PM GMT+01:00, "Christoph M. Becker" <
> > [email protected]> wrote:
> >
> > > This "try left/right" approach is how operator overloading works
> > > for
> > > internal classes[1], and apparently, it works quite well, as long
> > > as it
> > > is not overused.
> >
> > The fact that it works in one or two cases as an implementation
> > detail where the full implementation is controlled by a single
> > group (internals) is no indication for it to work at large.
>
> Fair enough. But maybe Python, where userland operator overloading
> works similar to the proposal at hand, is? :)
It doesn't:
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def __add__(self, other):
... print("add")
...
>>> a = A()
>>> a + 1
add
>>> 1 + a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'A'
johannes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php