Re: [RFC] User-defined object comparison
| From: | Levi Morrison | Date: | Wed, 27 Jun 2018 18:24:08 +0000 |
| Subject: | Re: [RFC] User-defined object comparison | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102501@lists.php.net to get a copy of this message | ||
On Tue, Jun 26, 2018 at 5:50 PM Rudolf Theunissen
<rudolf.theunissen@gmail.com> wrote:
>
> Hi everyone,
>
> This is an RFC that is based on previous discussions here:
> https://externals.io/message/102337
>
> RFC: https://wiki.php.net/rfc/object-comparison
>
> The implementation is tested and appears to be working as expected. :)
I had some off-list contact with Rudi and generally have agreed with
these changes.
However, there may be some value in following Python's lead. In Python
2 they had a
__cmp__ magic method and in Python 3 they removed it
and added all of these:
__lt__
__le__
__eq__
__ne__
__gt__
__ge__
This permits things such as NumPy to overload < to do an element-wise
comparison of the members; something like this:
np.array([1, 3, 5, 7]) < np.array([2, 1, 6, 6])
// evaluates to np.array([true, false, true, false)
If we pursue this Pythonic route then we would also need methods for +
- * / % etc. I do not want to derail the conversation too much, but it
does seem opportune to discuss operator overloading more generally.