Bug #68897 [Opn->Asn]: Using variable for sort flag in array_multisort cause wrong results

From: Date: Sat, 24 Jan 2015 12:35:00 +0000
Subject: Bug #68897 [Opn->Asn]: 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-190172@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: kalle@php.net Reported by: jrbasso at gmail dot com Summary: Using variable for sort flag in array_multisort cause wrong results -Status: Open +Status: Assigned Type: Bug Package: Arrays related Operating System: Linux PHP Version: master-Git-2015-01-24 (Git) -Assigned To: +Assigned To: laruence Block user comment: N Private report: N New Comment: I think the behavior was undefined, right Laruence? Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#190172) next »