#39456 [NEW]: Upgrade to 5.2 causes different behaviour array_multisort

From: Date: Fri, 10 Nov 2006 09:36:48 +0000
Subject: #39456 [NEW]: Upgrade to 5.2 causes different behaviour array_multisort
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-104737@lists.php.net to get a copy of this message
From: ricardo dot matters at mindbench dot nl Operating system: debian cur 2.6.18-1-686-bigmem PHP version: 5.2.0 PHP Bug Type: Arrays related Bug description: Upgrade to 5.2 causes different behaviour array_multisort Description: ------------ To sort an multidimensional array, I'm using a wrapper for array_multisort. Was working just fine, but as from 5.2, nothing is being sorted. Documentation lacks any information if array_multisort has been changed. Reproduce code: --------------- function multisort() { $n = func_num_args(); $ar = func_get_arg($n-1); if (!is_array($ar)) return false; for ($i = 0; $i < $n-1; $i++) { $col[$i] = func_get_arg($i); } foreach($ar as $key => $val) { foreach($col as $kkey => $vval) { if (is_string($vval)) { ${"subar$kkey"}[$key] = $val[$vval]; } } } foreach($col as $key => $val) { $arv[] = (is_string($val) ? ${"subar$key"} : $val); } $arv[] = $ar; call_user_func_array("array_multisort", $arv); return $ar; } $ar = array( array('id' => 1, 'weight' => 78, 'ts' => 123456), array('id' => 1, 'weight' => 78, 'ts' => 123457), array('id' => 1, 'weight' => 98, 'ts' => 134526), array('id' => 1, 'weight' => 10, 'ts' => 112456), array('id' => 1, 'weight' => 56, 'ts' => 177776) ); print_r(multisort('weight', SORT_DESC, SORT_NUMERIC, 'ts', SORT_DESC, SORT_NUMERIC, $ar)); Expected result: ---------------- Array ( [0] => Array ( [id] => 1 [weight] => 98 [ts] => 134526 ) [1] => Array ( [id] => 1 [weight] => 78 [ts] => 123457 ) [2] => Array ( [id] => 1 [weight] => 78 [ts] => 123456 ) [3] => Array ( [id] => 1 [weight] => 56 [ts] => 177776 ) [4] => Array ( [id] => 1 [weight] => 10 [ts] => 112456 ) ) Actual result: -------------- Array ( [0] => Array ( [id] => 1 [weight] => 78 [ts] => 123456 ) [1] => Array ( [id] => 1 [weight] => 78 [ts] => 123457 ) [2] => Array ( [id] => 1 [weight] => 98 [ts] => 134526 ) [3] => Array ( [id] => 1 [weight] => 10 [ts] => 112456 ) [4] => Array ( [id] => 1 [weight] => 56 [ts] => 177776 ) ) -- Edit bug report at http://bugs.php.net/?id=39456&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39456&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39456&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39456&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39456&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39456&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39456&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39456&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39456&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39456&r=support Expected behavior: http://bugs.php.net/fix.php?id=39456&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39456&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39456&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39456&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39456&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39456&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39456&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39456&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39456&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39456&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39456&r=mysqlcfg

« previous php.bugs (#104737) next »