-
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
ksort(..., SORT_REGULAR)
behaves incorrectly on arrays with string and numeric keys since PHP 8.0
#9296
Comments
… 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.
* PHP-8.0: Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys
* PHP-8.1: Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys
@cmb69 Personally, I think this should be fixed in PHP 8.2 or later and marked as BC Break. |
The fix for this bug is already in commit cd1aed8 and will be present in PHPs 8.0.23, 8.1.10, and 8.2.0. |
Yes, I understand that. However, I think you should reconsider whether this is appropriate. Fortunately, none of the versions have been released yet. |
Ah, I thought you were asking about whether it was going to be fixed at all. Every bug fix breaks compatibility for someone. Personally, I don't think everybody should have to upgrade all the way to 8.2 to get this one just because there might be some people who have discovered and are making deliberate use of what is IMO objectively illogical behavior on PHP's part. |
I agree with your opinion, but I don't think this change should be made in a patch. This is a decision-making issue. Either way, I would like to get confirmation, so I will send an email to the ML. Thanks. |
… keys" This reverts commit cd1aed8, as discussed on internals (<https://externals.io/message/118483>).
* PHP-8.0: Revert "Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys"
* PHP-8.1: Revert "Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys"
… keys" This reverts commit cd1aed8, as discussed on internals (<https://externals.io/message/118483>).
… keys" This reverts commit cd1aed8, as discussed on internals (<https://externals.io/message/118483>).
… keys" This reverts commit cd1aed8, as discussed on internals (<https://externals.io/message/118483>).
Description
The behavior of the string and number comparison operators has been changed since php 8, but
ksort
andkrsort
functions still use the old rules.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.The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.0
Operating System
No response
The text was updated successfully, but these errors were encountered: