php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49241 error in code by array just after upgrade 5.3
Submitted: 2009-08-12 22:25 UTC Modified: 2009-08-12 23:19 UTC
From: yakucorp at gmail dot com Assigned:
Status: Not a bug Package: PHP options/info functions
PHP Version: 5.3.0 OS: centos 5.3
Private report: No CVE-ID: None
 [2009-08-12 22:25 UTC] yakucorp at gmail dot com
Description:
------------
I just upgrade my php v to 5.3 and it appears this error.
this is my old script, and returns error like this




Reproduce code:
---------------
function fn_array_multisort()
{
	$n = func_num_args();
	$ar = func_get_arg(0);
	if(!is_array($ar)){
		return false;
	}

	for($i = 1; $i < $n; $i++){
		$col[$i] = func_get_arg($i);
	}

	foreach($ar as $key => $val){
		foreach($col as $kkey => $vval){
			if(is_string($vval)){
				${"subar$kkey"}[$key] = isset($val[$vval]) ? $val[$vval] : '';
			}
		}
	}

	$arv = array();
	foreach($col as $key => $val){
		$arv[] = (is_string($val) ? ${"subar$key"} : $val);
	}
	$arv[] = $ar;
	call_user_func_array("array_multisort", $arv);

	return $ar;
}

Expected result:
----------------
Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /usr/local/nginx/html/fox/core/fn_common.php on line 2000

Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /usr/local/nginx/html/fox/core/fn_common.php on line 2000

Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /usr/local/nginx/html/fox/core/fn_common.php on line 2000

Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /usr/local/nginx/html/fox/core/fn_common.php on line 2000

Warning: Parameter 1 to array_multisort() expected to be a reference, value given in /usr/local/nginx/html/fox/core/fn_common.php on line 2000

Actual result:
--------------
call_user_func_array("array_multisort", $arv);

this line might be the clue call_user_func_array("array_multisort", $arv);
please help, thanks

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-12 22:54 UTC] scottmac@php.net
The manual says about call_user_func_array():
"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. "


array_multisort expects an array by reference, but when you use call_user_func_array in your code its not a reference just a regular variable.

This worked by accident in PHP 5.2.


 [2009-08-12 22:57 UTC] yakucorp at gmail dot com
Thanks for fast reply, then how to fix it?
i just delete call_user_func_array("array_multisort", $arv);

and the error is not appears, but how to fix this thing?
thanks
 [2009-08-12 23:19 UTC] scottmac@php.net
When you assign to $arv[] do so by reference.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC