On Fri, Mar 6, 2020 at 12:58 AM Andrea Faulds <a...@ajf.me> wrote:

> Hi,
>
> Nikita Popov wrote:
> >
> > I've implemented this variant now. If the comparison function returns a
> > boolean, you get
> >
> >> Deprecated: usort(): Returning bool from comparison function is
> > deprecated, return one of -1, 0 or 1 instead in %s on line %d
> >
> > once per usort() call, and we retry with swapped operands to ensure
> > compatibility.
> >
> > Regards,
> > Nikita
> >
>
> I think that message could be a little misleading, because any negative
> or positive value is valid, not just those of magnitude 1, right? IIRC
> strcmp($a, $b) doesn't just return -1 and 1, and of course this is also
> the case for the classic ($a - $b).
>

I've update the message to say:

> Deprecated: usort(): Returning bool from comparison function is
deprecated, return an integer less than, equal to, or larger than zero in
%s on line %d

The astute reader will notice that this is equivalent to "any integer", but
I think phrased this way, the meaning should be clear to anyone familiar
with the basic concept of comparison functions, while not mentioning -1, 0
and 1 in particular.

Regards,
Nikita

PS: Yes, I'm aware that you can also return a floating point number. No,
you should definitely not do that, because it's going to get casted to an
integer and produce wrong results if the numbers get large enough.

Reply via email to