Bug #68897 [Asn->Csd]: Using variable for sort flag in array_multisort cause wrong results
| From: | laruence@php.net | Date: | Sat, 24 Jan 2015 14:52:10 +0000 |
| Subject: | Bug #68897 [Asn->Csd]: Using variable for sort flag in array_multisort cause wrong results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190177@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68897&edit=1
ID: 68897
Updated by: laruence@php.net
Reported by: jrbasso at gmail dot com
Summary: Using variable for sort flag in array_multisort
cause wrong results
-Status: Assigned
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: master-Git-2015-01-24 (Git)
Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a98fd7125ac9165822fa34a01e35a97a2076c3b9
Log: Fixed bug #68897 (Using variable for sort flag in array_multisort cause wrong results)
Previous Comments:
------------------------------------------------------------------------
[2015-01-24 12:35:00] kalle@php.net
I think the behavior was undefined, right Laruence?
------------------------------------------------------------------------
[2015-01-24 05:51:13] jrbasso at gmail dot com
Description:
------------
Using master rev. be5337421680f059f7b23dd530645e070b15715a the array_multisort have incorrect
behavior if the SORT direction flag is passed in a variable.
This behavior is ok on HHVM and until PHP 5.6. See http://3v4l.org/7pU0u
Test script:
---------------
// Works
$values = array("Lindsay", "Nate");
array_multisort($values, SORT_DESC, SORT_REGULAR, array(0, 1), SORT_DESC, SORT_REGULAR);
var_dump($values);
// Doesn't work
$values = array("Lindsay", "Nate");
$dir = SORT_DESC;
array_multisort($values, $dir, SORT_REGULAR, array(0, 1), $dir, SORT_REGULAR);
var_dump($values);
Expected result:
----------------
array(2) {
[0]=>
string(4) "Nate"
[1]=>
string(7) "Lindsay"
}
array(2) {
[0]=>
string(4) "Nate"
[1]=>
string(7) "Lindsay"
}
Actual result:
--------------
array(2) {
[0]=>
string(4) "Nate"
[1]=>
string(7) "Lindsay"
}
array(2) {
[0]=>
string(7) "Lindsay"
[1]=>
string(4) "Nate"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68897&edit=1