ID:               49241
 Updated by:       scott...@php.net
 Reported By:      yakucorp at gmail dot com
 Status:           Bogus
 Bug Type:         PHP options/info functions
 Operating System: centos 5.3
 PHP Version:      5.3.0
 New Comment:

When you assign to $arv[] do so by reference.


Previous Comments:
------------------------------------------------------------------------

[2009-08-12 22:57:30] 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 22:54:40] scott...@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:25:43] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49241&edit=1

Reply via email to