Re: [RFC] [VOTE] User-defined object comparison

From: Date: Tue, 10 Jul 2018 14:45:19 +0000
Subject: Re: [RFC] [VOTE] User-defined object comparison
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-102716@lists.php.net to get a copy of this message
Hi everyone, I had a chat with Levi yesterday about the operator overloading side of this RFC, and I'd like to try explain it as clearly as I can so that there is no confusion. Using <=> spaceship operator as an example, the operator is like a pointer that references the internal compare_function. When you use the operator, it calls that function, which in turn does comparison tests and eventually calls object handlers when comparing objects. This RFC is not suggesting that we change the pointer of the operator, but instead adjust the behaviour of compare_function, which the operator already points to. Implementing __compareTo does affect the behaviour of the operator, but it doesn't overload it. If in the future we wanted to add proper operator overloading, there would be a function like __spaceship that directly overloads the operator to change its pointer to something else. If this was to happen, __compareTo would still be used by compare_function, and used internally when sorting or searching. I realise that the behaviour of the operator can be changed with __compareTo, and is therefore no different to operator overloading, but that's not how we should look at this. The reason why <=> normalises to -1,0,1 isn't because the operator dictates that - it's compare_function that does that, which is what the operator points to by default. I hope that helps to clear things up a bit. :) On Mon, 9 Jul 2018 at 13:57, Rudolf Theunissen <rudolf.theunissen@gmail.com> wrote: > Hi everyone, > > With no further discussion and no objection to start voting on this RFC, I > would like to move forward with the vote, which requires a 2/3 majority to > pass. > > *RFC*: https://wiki.php.net/rfc/object-comparison > > Discussions: > - https://externals.io/message/102337 > <https://externals.io/message/102389> (June 21) > - https://externals.io/message/102473 (June 26) > > The vote will be open until 2018-07-16. > > Thank you, > Rudi > >

« previous php.internals (#102716) next »