note 97897 added to function.call-user-func
| From: | pablobm at gmail dot com | Date: | Fri, 14 May 2010 10:10:26 +0000 |
| Subject: | note 97897 added to function.call-user-func | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169236@lists.php.net to get a copy of this message | ||
Further to Maxdamantus's comment, this is another example of what works and what doesn't
when some of the parameters are expected to be passed by reference:
<?php
$alphabet = array(
'a' => 'alpha',
'b' => 'beta',
);
function add_letter(&$a, $roman, $greek_name) {
$a[$roman] = $greek_name;
}
// Gives warning and doesn't work
call_user_func('add_letter', $alphabet, 'c', 'gamma');
print_r($alphabet);
// Works
call_user_func('add_letter', &$alphabet, 'd', 'delta');
print_r($alphabet);
// Works
$func_name = 'add_letter';
$func_name($alphabet, 'e', 'epsilon');
print_r($alphabet);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 94.193.96.179
----
Manual Page -- http://www.php.net/manual/en/function.call-user-func.php
Edit -- https://master.php.net/note/edit/97897
Del: integrated -- https://master.php.net/note/delete/97897/integrated
Del: useless -- https://master.php.net/note/delete/97897/useless
Del: bad code -- https://master.php.net/note/delete/97897/bad+code
Del: spam -- https://master.php.net/note/delete/97897/spam
Del: non-english -- https://master.php.net/note/delete/97897/non-english
Del: in docs -- https://master.php.net/note/delete/97897/in+docs
Del: other reasons-- https://master.php.net/note/delete/97897
Reject -- https://master.php.net/note/reject/97897
Search -- https://master.php.net/manage/user-notes.php