[php-src] Issue #9296: `ksort(..., SORT_REGULAR)` behaves incorrectly on arrays with string and numeric keys since PHP 8.0
| From: | Ramzeeset | Date: | Thu, 11 Aug 2022 11:38:43 +0000 |
| Subject: | [php-src] Issue #9296: `ksort(..., SORT_REGULAR)` behaves incorrectly on arrays with string and numeric keys since PHP 8.0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242178@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9296
Author: Ramzeeset
### Description
The behavior of the string and number comparison operators has been changed since php 8, but
ksort and krsort 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:
```php
<?php
$array = ["600" => 0, "aaa" => 1];
ksort($array, SORT_REGULAR);
var_dump($array);
var_dump(array_key_first($array) <=> array_key_last($array));
```
Resulted in this output:
```
array(2) {
["aaa"]=>
int(1)
[600]=>
int(0)
}
int(1)
```
But I expected this output instead:
```
array(2) {
[600]=>
int(0)
["aaa"]=>
int(1)
}
int(-1)
```
### PHP Version
PHP 8.0
### Operating System
_No response_