php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71054 arsort() function backward incompatible.
Submitted: 2015-12-08 08:37 UTC Modified: 2015-12-09 00:21 UTC
From: spongi1019 at naver dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.0.0 OS: CentOS 5.9
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spongi1019 at naver dot com
New email:
PHP Version: OS:

 

 [2015-12-08 08:37 UTC] 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)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-08 10:31 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2015-12-08 10:31 UTC] 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 14:46 UTC] rasmus@php.net
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.
 [2015-12-09 00:21 UTC] spongi1019 at naver dot com
Thank you so much for your reply
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC