Hi Nikita!
Nikita Popov wrote:
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
> On Mar 4, 2020, at 11:42 AM, Nikita Popov wrote:
>
> Hi internals,
>
> Sorting function in PHP currently do not guarantee stability, which means
> that the result order of elements that compare equal is not defined.
>
>
>
> What do people think about this? Is there interest in making so
On Wed, Mar 4, 2020 at 8:49 PM Larry Garfield
wrote:
> On Wed, Mar 4, 2020, at 12:35 PM, Sara Golemon wrote:
> > On Wed, Mar 4, 2020 at 12:12 PM Nikita Popov
> wrote:
> >
> > > On Wed, Mar 4, 2020 at 6:17 PM Sara Golemon wrote:
> > >
> > >> On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov
> > >> w
On Fri, Mar 6, 2020 at 12:58 AM Andrea Faulds 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
Hi!
> Given that we have internal classes which deliberately have such
> comparison behavior (i.e. returning 0 or 1, to signal that there is no
> order defined), e.g. Closures[1], I tend to prefer raising a warning
> instead of trying to recover.
I think there weirdness is because equality and co
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 ope
On 05.03.2020 at 13:05, Nikita Popov wrote:
>> Given that we have internal classes which deliberately have such
>> comparison behavior (i.e. returning 0 or 1, to signal that there is no
>> order defined), e.g. Closures[1], I tend to prefer raising a warning
>> instead of trying to recover.
>>
>> [
On Wed, Mar 4, 2020 at 11:12 PM Christoph M. Becker
wrote:
> On 04.03.2020 at 19:11, Nikita Popov wrote:
>
> > 1. As Tyson suggests, we can throw a warning if a boolean is returned
> from
> > the comparison callback (probably with a check to only throw it once per
> > sort), to make it obvious wh
On Wed, Mar 4, 2020 at 7:35 PM Sara Golemon wrote:
> On Wed, Mar 4, 2020 at 12:12 PM Nikita Popov wrote:
>
>> On Wed, Mar 4, 2020 at 6:17 PM Sara Golemon wrote:
>>
>>> On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov
>>> wrote:
>>>
The only issue I ran into is that this change has a negative
t too large, it is better to have a
single behavior, rather than adding more flags to our (many) sort functions.
Regards,
Nikita
> --
> *From:* Nikita Popov
> *Sent:* Wednesday, March 4, 2020 19:42
> *To:* PHP internals
> *Subject:* [PHP-DEV] Make sor
Christoph M. Becker wrote:
Given that we have internal classes which deliberately have such
comparison behavior (i.e. returning 0 or 1, to signal that there is no
order defined), e.g. Closures[1], I tend to prefer raising a warning
instead of trying to recover.
Oof… I wonder if we should make F
On 04.03.2020 at 19:11, Nikita Popov wrote:
> 1. As Tyson suggests, we can throw a warning if a boolean is returned from
> the comparison callback (probably with a check to only throw it once per
> sort), to make it obvious what the cause is.
>
> 2. We can fix this transparently by doing something
Hi,
Larry Garfield wrote:
If I'm understanding the definition of stable here, it means that if two values
evaluate to equal they will always end up in the same order in the output that
they were in the input, yes? So (trivial example):
$a = ["3", 2, 3, 5];
Sorts to:
[2, "3", 3, 5];
always
Note that a comparison callback can also be broken in other ways:
- It could contain a loop, e.g. 'a' < 'b', 'b' < 'c', 'c' < 'a'.
- It could have alternating return values in subsequent calls with the same
arguments.
This kind of misbehavior cannot be easily detected.
The best we can do is make s
On Wed, Mar 4, 2020, at 12:35 PM, Sara Golemon wrote:
> On Wed, Mar 4, 2020 at 12:12 PM Nikita Popov wrote:
>
> > On Wed, Mar 4, 2020 at 6:17 PM Sara Golemon wrote:
> >
> >> On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov
> >> wrote:
> >>
> >>> The only issue I ran into is that this change has a n
On Wed, Mar 4, 2020 at 12:12 PM Nikita Popov wrote:
> On Wed, Mar 4, 2020 at 6:17 PM Sara Golemon wrote:
>
>> On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov
>> wrote:
>>
>>> The only issue I ran into is that this change has a negative impact on
>>> code
>>> using illegal comparison callbacks like
On Wed, Mar 4, 2020 at 6:17 PM Sara Golemon wrote:
> On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov wrote:
>
>> The only issue I ran into is that this change has a negative impact on
>> code
>> using illegal comparison callbacks like this:
>>
>> usort($array, function($a, $b) {
>> return $a >
Le mer. 4 mars 2020 à 18:30, tyson andre a
écrit :
> > What do people think about this? Is there interest in making sorting
> > stable? Is it okay to break code using illegal comparison callbacks?
>
> I'd be interested in having a stable sort.
>
A new SORT_STABLE flag would be great!
> What do people think about this? Is there interest in making sorting
> stable? Is it okay to break code using illegal comparison callbacks?
I'd be interested in having a stable sort.
When migrating from php 5.6 to 7 a long time ago,
the fact that sorting was no longer stable was an inconvenience
On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov wrote:
> The only issue I ran into is that this change has a negative impact on code
> using illegal comparison callbacks like this:
>
> usort($array, function($a, $b) {
> return $a > $b;
> });
>
> Let's define what "negative impact" means in this
Hi internals,
Sorting function in PHP currently do not guarantee stability, which means
that the result order of elements that compare equal is not defined.
To achieve a stable sort, you need to do something like this (untested):
$arrayAndPos = [];
$pos = 0;
foreach ($array as $value) {
$arr
21 matches
Mail list logo