|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-08-25 06:42 UTC] jani@php.net
[2009-08-25 14:54 UTC] ws at develtheory dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 17:00:01 2025 UTC |
Description: ------------ Warning: Parameter 2 to array_multisort() expected to be a reference, value given I realize tickets similar to this (#49069, #49241) have already been marked as bogus, but I'm not finding a good solution or explanation of call_user_func_array's breakage of this between 5.2 and 5.3. The documentation of call_user_func_array describes it as such: "Note: Referenced variables in param_arr are passed to the function by a reference, others are passed by a value. In other words, it does not depend on the function signature whether the parameter is passed by a value or by a reference." This in mind, I'm not sure why SORT_ASC or SORT_REGULAR would _ever_ need to be sent in as a reference. This perplexes me. It seems to me like a properly referenced array should pass in fine. Had weierophinney@php.net written the $args line in OP #49069 as such: $args = array(&$array1, $sort1a, $sort1b, &$array2, $sort2a, $sort2b, &$array3); it should work, right? I have attached example code that in my eyes (and others in #php.pecl and #phpc) should work in 5.3 and does already work in 5.2. Since weierophinney@php.net did not provide a fix in that ticket, could someone point me to a solution, should the functionality still be sans-bug? Reproduce code: --------------- /* first name params */ $fnames = array('9'=>'FirstOne', '2'=>'FirstTwo'); $fsort = SORT_DESC; $fsort_type = SORT_STRING; /* the array itself */ $the_array = array( '9' => array( 'id'=>'9', 'first_name'=>'FirstOne', 'last_name'=>'LastOne' ), '4' => array( 'id'=>'4', 'first_name'=>'FirstTwo', 'last_name'=>'LastTwo' ) ); $params[] = &$fnames; $params[] = $fsort; $params[] = $fsort_type; $params[] = &$the_array; call_user_func_array('array_multisort', $params); //sends warning, doesn't sort properly //array_multisort(&$fnames, $fsort, $fsort_type, &$the_array); //works fine var_dump($the_array); Expected result: ---------------- array 0 => array 'id' => string '4' (length=1) 'first_name' => string 'FirstTwo' (length=8) 'last_name' => string 'LastTwo' (length=7) 1 => array 'id' => string '9' (length=1) 'first_name' => string 'FirstOne' (length=8) 'last_name' => string 'LastOne' (length=7) Actual result: -------------- Parameter 2 to array_multisort() expected to be a reference, value given array 0 => array 'id' => string '9' (length=1) 'first_name' => string 'FirstOne' (length=8) 'last_name' => string 'LastOne' (length=7) 1 => array 'id' => string '4' (length=1) 'first_name' => string 'FirstTwo' (length=8) 'last_name' => string 'LastTwo' (length=7)