#43079 [NEW]: call_user_func_array(): documentation for pass-by-value/pass-by-ref behaviour

From: Date: Tue, 23 Oct 2007 09:34:30 +0000
Subject: #43079 [NEW]: call_user_func_array(): documentation for pass-by-value/pass-by-ref behaviour
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-167@lists.php.net to get a copy of this message
From: robin_fernandes at uk dot ibm dot com Operating system: Windows PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: call_user_func_array(): documentation for pass-by-value/pass-by-ref behaviour Description: ------------ The documentation for call_user_func_array() makes no mention of pass-by-value / pass-by-reference (unlike call_user_func(), which is very clear on this subject). This is significant because the behaviour of call_user_func_array() is not intuitive (see the user contributed notes on the documentation page: http://php.net/call_user_func_array ). It appears that the way in which an argument is passed depends not on the target function signature, but rather on whether its entry in $param_arr is referenced or not. Specifically, it is possible to force an argument to be passed by reference to a function which expects a pass-by-value argument, even with call time pass by reference DISABLED in php.ini. See the reproduce code snippet for an example. The most succinct way I'm able to express this is: "Regardless of the callback function's signature, any member of $param_arr that is referenced will be passed by reference and any member that is not reference will be passed by value." I'm assuming this behaviour is intentional. If not I'll happily raise a scripting engine bug - let me know. Reproduce code: --------------- <?php function byRef(&$a, &$b) { $a = 'changed'; $b = 'changed.b'; } function byVal($a, $b) { $a = 'changed.a'; $b = 'changed.b'; } echo "\nForce a pass-by-reference function to take args by value:\n"; $args = array('original.a', 'original.b'); call_user_func_array('byRef', $args); var_dump($args); echo "\nForce a pass-by-Value function to take one arg by reference:\n"; echo "NOTE: this works even with call time pass by reference DISABLED in php.ini:\n"; $args = array('original.a', 'original.b'); $ref = &$args[0]; call_user_func_array('byVal', $args); var_dump($args); ?> Expected result: ---------------- Force a pass-by-reference function to take args by value: array(2) { [0]=> string(10) "original.a" [1]=> string(10) "original.b" } Force a pass-by-Value function to take one arg by reference: NOTE: this works even with call time pass by reference DISABLED in php.ini: array(2) { [0]=> &string(9) "changed.a" [1]=> string(10) "original.b" } Actual result: -------------- N/A -- Edit bug report at http://bugs.php.net/?id=43079&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43079&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43079&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43079&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43079&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43079&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43079&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43079&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43079&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43079&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43079&r=support Expected behavior: http://bugs.php.net/fix.php?id=43079&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43079&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43079&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43079&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43079&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43079&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43079&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43079&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43079&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43079&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43079&r=mysqlcfg

« previous php.doc.bugs (#167) next »