-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-9296: incorrect ksort(..., SORT_REGULAR)
behaviour on arrays with numeric and string keys
#9293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh! I'm pretty confused that this apparently has not been reported before.
007484a
to
a12ec5e
Compare
I think this is a bug and it's better to report it at https://github.com/php/php-src/issues I would prefer, to keep the old (optimized) comparison code at least for numeric+numeric and string+string keys, and fallback to It would be also great to have a separate test case with a reference to the issue report. |
ksort(..., SORT_REGULAR)
behaviour on arrays with numeric and string keysksort(..., SORT_REGULAR)
behaviour on arrays with numeric and string keys
… numeric keys The comparator function used at ksort in SORT_REGULAR mode need to be consistent with basic comparison rules. These rules were changed in PHP-8.0 for numeric strings, but comparator used at ksort kept the old behaviour. It leads to inconsistent situations, when after ksort the first key is GREATER than some of the next ones by according to the basic comparison operators.
a12ec5e
to
23fc6d4
Compare
Done with the bug report, see #9296
Fixed at aa125c8
Added at 23fc6d4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this looks fine.
Thank you! |
The comparator function used at
ksort
orkrsort
inSORT_REGULAR
mode need to be consistent with basic comparison rules.These rules were changed in PHP-8.0 for numeric strings, but comparator used at
ksort
mistakenly kept the old behaviour.It leads to inconsistent situations, when after
ksort
the first key is GREATER than some of the next ones by according to the basic comparison operators.Simple example:
In php7.4 we get:
That's OK, because it's consistent with php7.4 comparison rules.
In php8.0 the output is:
Which is not OK, because it is not consistent with new php8.0 comparison rules.
After this fix the output is:
Which is consistent with php8.0 comparison rules.
See #9296