note 45310 modified in language.references.pass by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Jan 2010 13:21:50 +0000 |
| Subject: | note 45310 modified in language.references.pass by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165427@lists.php.net to get a copy of this message | ||
Passing arrays by reference doesn't work as I expected from within call_user_func.
I had:
<?php
$arr = Array();
call_user_func(Array("ClassName","functionName"), $param1, $param2, $arr);
print_r($arr);
class ClassName {
functionName($param1, $param2, &$arr) {
$arr[0] = "apple";
$arr[1] = "banana";
print_r($arr);
}
}
?>
I expected the output to be like:
Array ( [0] => "apple" [1] => "banana" )
Array ( [0] => "apple" [1] => "banana" )
but instead it was only:
Array ( [0] => "apple" [1] => "banana" )
However, when I changed the function call to plain old:
<?php
$arr = Array();
ClassName::functionName($param1,$param2,$arr);
print_r($arr);
?>
Output was the expected:
Array ( [0] => "apple" [1] => "banana" )
Array ( [0] => "apple" [1] => "banana" )
--was--
Passing arrays by reference doesn't work as I expected from within call_user_func.
I had:
<?
$arr = Array();
call_user_func(Array("ClassName","functionName"), $param1, $param2, $arr);
print_r($arr);
class ClassName {
functionName($param1, $param2, &$arr) {
$arr[0] = "apple";
$arr[1] = "banana";
print_r($arr);
}
}
?>
I expected the output to be like:
Array ( [0] => "apple" [1] => "banana" )
Array ( [0] => "apple" [1] => "banana" )
but instead it was only:
Array ( [0] => "apple" [1] => "banana" )
However, when I changed the function call to plain old:
<?
$arr = Array();
ClassName::functionName($param1,$param2,$arr);
print_r($arr);
?>
Output was the expected:
Array ( [0] => "apple" [1] => "banana" )
Array ( [0] => "apple" [1] => "banana" )
http://php.net/manual/en/language.references.pass.php