note 99549 added to language.references.pass
| From: | northhero at gmail dot com | Date: | Tue, 24 Aug 2010 07:25:17 +0000 |
| Subject: | note 99549 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171964@lists.php.net to get a copy of this message | ||
Someone mentioned that passing reference doesn't work as expected from within
call_user_func(). For example:
$string = 'string';
function change(&$str) {
$str = 'str';
}
call_user_func('change', $string);
echo $string;
output:
string //not as expected 'str'
Here we could assume call_user_func as below
function call_user_funct($func, $param) {
$func($param);
}
As calling $func() inside call_user_funct, here is change(), the variable $param is copied to a
third variable then the temp variable is passed to the $func. So $str only hold the reference of the
temp variable inside change().
Of course , if we pass &$string directly to call_user_func we could always get the result as
expected (str).
----
Server IP: 61.195.146.164
Probable Submitter: 126.112.211.154
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit -- https://master.php.net/note/edit/99549
Del: integrated -- https://master.php.net/note/delete/99549/integrated
Del: useless -- https://master.php.net/note/delete/99549/useless
Del: bad code -- https://master.php.net/note/delete/99549/bad+code
Del: spam -- https://master.php.net/note/delete/99549/spam
Del: non-english -- https://master.php.net/note/delete/99549/non-english
Del: in docs -- https://master.php.net/note/delete/99549/in+docs
Del: other reasons-- https://master.php.net/note/delete/99549
Reject -- https://master.php.net/note/reject/99549
Search -- https://master.php.net/manage/user-notes.php