note 99549 deleted from language.references.pass by googleguy

From: Date: Sun, 23 Feb 2014 17:24:11 +0000
Subject: note 99549 deleted from language.references.pass by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198613@lists.php.net to get a copy of this message
Note Submitter: northhero at gmail dot com ---- Someone mentioned that passing reference doesn't work as expected from within call_user_func(). For example: <?php $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 <?php 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).

« previous php.notes (#198613) next »