note 45310 added to language.references.pass

From: Date: Wed, 01 Sep 2004 21:27:39 +0000
Subject: note 45310 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-75899@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: <? $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" ) ---- Manual Page -- http://www.php.net/manual/en/language.references.pass.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45310 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45310&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45310&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75899) next »