Req #71054 [Nab]: arsort() function backward incompatible.
Edit report at https://bugs.php.net/bug.php?id=71054&edit=1
ID: 71054
Updated by: rasmus@php.net
Reported by: spongi1019 at naver dot com
Summary: arsort() function backward incompatible.
Status: Not a bug
Type: Feature/Change Request
Package: Arrays related
Operating System: CentOS 5.9
PHP Version: 7.0.0
Block user comment: N
Private report: N
New Comment:
The manual page that is relevant here is:
http://php.net/manual/en/array.sorting.php
Specifically the line that says:
If any of these sort functions evaluates two members as equal then the order is undefined (the
sorting is not stable).
So that test of yours relies on undefined behaviour.
Previous Comments:
------------------------------------------------------------------------
[2015-12-08 10:31:10] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
we are using stable sorting algo for elements less 16(actually we will split elements into 16 by
using un-stable sorting algo)
------------------------------------------------------------------------
[2015-12-08 08:37:07] spongi1019 at naver dot com
Description:
------------
All the same, the value of element
Non-compatible features have been found in the function.
arsort()
PHP 5.2 ~ 5.6 result
----
array(4) {
["d"]=>
int(1)
["c"]=>
int(1)
["z"]=>
int(1)
["a"]=>
int(1)
}
PHP 7.0 result
----
array(4) {
["a"]=>
int(1)
["z"]=>
int(1)
["c"]=>
int(1)
["d"]=>
int(1)
}
Test script:
---------------
<?php
$arr = array(
'a' => 1,
'z' => 1,
'c' => 1,
'd' => 1
);
arsort($arr);
var_dump($arr);
Expected result:
----------------
array(4) {
["d"]=>
int(1)
["c"]=>
int(1)
["z"]=>
int(1)
["a"]=>
int(1)
}
Actual result:
--------------
array(4) {
["a"]=>
int(1)
["z"]=>
int(1)
["c"]=>
int(1)
["d"]=>
int(1)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71054&edit=1
Thread (4 messages)