Req #71054 [Nab]: arsort() function backward incompatible.

From: Date: Wed, 09 Dec 2015 00:21:56 +0000
Subject: Req #71054 [Nab]: arsort() function backward incompatible.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197711@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71054&edit=1

 ID:                 71054
 User updated by:    spongi1019 at naver dot com
 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:

Thank you so much for your reply


Previous Comments:
------------------------------------------------------------------------
[2015-12-08 14:46:07] 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-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)

« previous php.bugs (#197711) next »