#49353 [NEW]: call_user_array_func()/array_multisort()

From: Date: Tue, 25 Aug 2009 01:29:11 +0000
Subject: #49353 [NEW]: call_user_array_func()/array_multisort()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-141461@lists.php.net to get a copy of this message
From: ws at develtheory dot com Operating system: Cent5 PHP version: 5.3.0 PHP Bug Type: Arrays related Bug description: call_user_array_func()/array_multisort() 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) -- Edit bug report at http://bugs.php.net/?id=49353&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49353&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49353&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49353&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49353&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49353&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49353&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49353&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49353&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49353&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49353&r=support Expected behavior: http://bugs.php.net/fix.php?id=49353&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49353&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49353&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49353&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49353&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49353&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49353&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49353&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49353&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49353&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49353&r=mysqlcfg

« previous php.bugs (#141461) next »