#43484 [NEW]: call_user_func_array(): questionable pass-by-val/pass-by-ref behaviour.
| From: | robin_fernandes at uk dot ibm dot com | Date: | Mon, 03 Dec 2007 14:09:12 +0000 |
| Subject: | #43484 [NEW]: call_user_func_array(): questionable pass-by-val/pass-by-ref behaviour. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-120313@lists.php.net to get a copy of this message | ||
From: robin_fernandes at uk dot ibm dot com
Operating system: Windows
PHP version: 5.3CVS-2007-12-03 (snap)
PHP Bug Type: Scripting Engine problem
Bug description: call_user_func_array(): questionable pass-by-val/pass-by-ref behaviour.
Description:
------------
This issue was originally raised as documentation bug 43079. Raising as
Scripting Engine problem as suggested by vrana at php dot net.
The pass-by-value/pass-by-ref 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.
Reproduced on php5.3 and php6 snaps on Windows.
Reproduce code:
---------------
<?php
function byRef(&$a, &$b) {
$a = 'changed.a';
$b = 'changed.b';
}
function byVal($a, $b) {
$a = 'changed.a';
$b = 'changed.b';
}
//Currently, this forces a pass-by-ref function to take args by val:
$args = array('original.a', 'original.b');
call_user_func_array('byRef', $args);
var_dump($args);
//Currently, this forces a pass-by-val function to take 1 arg by ref.
//This works even with call-time pass-by-ref DISABLED in php.ini.
$args = array('original.a', 'original.b');
$ref = &$args[0];
call_user_func_array('byVal', $args);
var_dump($args);
?>
Expected result:
----------------
array(2) {
[0]=>
string(9) "changed.a"
[1]=>
string(9) "changed.b"
}
array(2) {
[0]=>
&string(10) "original.a"
[1]=>
string(10) "original.b"
}
Actual result:
--------------
array(2) {
[0]=>
string(10) "original.a"
[1]=>
string(10) "original.b"
}
array(2) {
[0]=>
&string(9) "changed.a"
[1]=>
string(10) "original.b"
}
--
Edit bug report at http://bugs.php.net/?id=43484&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43484&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43484&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43484&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43484&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43484&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=43484&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43484&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43484&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43484&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43484&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43484&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=43484&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=43484&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43484&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43484&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43484&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43484&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43484&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43484&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43484&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43484&r=mysqlcfg