note 45310 deleted from language.references.pass by googleguy
| From: | googleguy@php.net | Date: | Sun, 23 Feb 2014 17:22:51 +0000 |
| Subject: | note 45310 deleted from language.references.pass by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198611@lists.php.net to get a copy of this message | ||
Note Submitter: ben at mekhaye dot net
----
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" )