Re: Equality and relative ordering of objects
| From: | Rudi Theunissen | Date: | Fri, 22 Jun 2018 13:55:53 +0000 |
| Subject: | Re: Equality and relative ordering of objects | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102370@lists.php.net to get a copy of this message | ||
>
> In my opinion we should have functions which take comparator and/or
> equality functions as parameters even if we can override these
> operators.
I really like this idea, because it puts the responsibility of the
definition on the caller. It
allows you to do things like "Is there an instance of X in this array that
has a value of Y greater than Z".
This is probably a candidate for a separate proposal though, perhaps even
in favour of this one. In saying
that, I still believe that there's a place for dynamic comparison and
equality if used responsibly. I see the
primary value in objects that have a specific, obvious value, such as money
or dimensions.
On Fri, 22 Jun 2018 at 08:43, Levi Morrison <morrison.levi@gmail.com> wrote:
> On Fri, Jun 22, 2018 at 6:39 AM Levi Morrison <levim@php.net> wrote:
> >
> >
> > > 1. You can't override the behaviour of
<,
> > > <=, >,
> > > >=, ==,
> > > !=
> > > with a userland implementation.
> > > 2. Therefore, you won't be able to affect the internals of array
> functions
> > > like in_array, sort
> > > etc.
> >
> > In my opinion we should have functions which take comparator and/or
> equality functions as parameters even if we can override these operators.
> I'd like to see an outline of such a plan as part of this RFC or as a
> precursor to it.
>
> (I know some already have this option, such as usort, but we don't
> have an in_array that takes an equality callback, correct?)
>