Re: [VOTE] Userspace operator overloading

From: Date: Thu, 09 Apr 2020 13:02:26 +0000
Subject: Re: [VOTE] Userspace operator overloading
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-109583@lists.php.net to get a copy of this message
On 09.04.2020 at 14:41, Dan Ackroyd wrote: > On Thu, 9 Apr 2020 at 13:18, Dan Ackroyd <Danack@basereality.com> wrote: > >> It appears to be the same error case as: >> > > And that code had a mistake. Should have been: > > ``` > class A { > public function add(A $rhs) {...} > } > > class B { > public function add(A|B $rhs) {...} > } > > $a = new A; > $b = new B; > > $b->add($a); // Ok > $a->add($b); // TypeError > ``` If we'd go with (dynamic) methods, wouldn't we have to add "r"-methods (like Python does) as well? And if we did so, wouldn't we encourage misusing operator overloading for all kinds of stuff (for which it shouldn't be used, in my opinion)? -- Christoph M. Becker

« previous php.internals (#109583) next »