|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-27 04:25 UTC] rasmus@php.net
[2009-07-27 08:53 UTC] jani@php.net
[2009-07-27 11:54 UTC] weierophinney@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 23:00:01 2025 UTC |
Description: ------------ Prior to 5.3.0, array_multisort() expected no references; the last array provided would be assumed to be a reference, and updated by the function during processing. Starting in 5.3.0, array_multisort() now expects all arguments to be passed by reference, raising a warning if it detects any are passed by copy. This also includes the various sort flags (which simply does not make sense, since the SORT_* constants are typically passed directly). In the reproduce code below, if you pass all arguments by reference, you get the expected result. However, this is a BC break from previous versions of PHP, as you were not required to pass by reference. An additional BC break occurs with the results: if you ignore the warning, the results returned differ from what was returned prior to 5.3 (this is shown below). You will only get the expected results if, again, all arguments are passed by reference. Reproduce code: --------------- $array1 = array('foo', 'bar', 'baz'); $array2 = array('baz', 'bar', 'foo'); $array3 = array('Foo', 'Bar', 'Baz'); $sort1a = SORT_ASC; $sort1b = SORT_STRING; $sort2a = SORT_ASC; $sort2b = SORT_REGULAR; $args = array($array1, $sort1a, $sort1b, $array2, $sort2a, $sort2b, &$array3); call_user_func_array('array_multisort', $args); var_export($array3); Expected result: ---------------- array ( 0 => 'Bar', 1 => 'Baz', 2 => 'Foo', ) Actual result: -------------- Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /home/matthew/tmp/test.php on line 23 array ( 0 => 'Foo', 1 => 'Bar', 2 => 'Baz', )