#50394 [Opn->Tbd]: Reference argument converted to value in __call (regression from 5.3.0)
| From: | jani@php.net | Date: | Mon, 07 Dec 2009 08:00:06 +0000 |
| Subject: | #50394 [Opn->Tbd]: Reference argument converted to value in __call (regression from 5.3.0) | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3409@lists.php.net to get a copy of this message | ||
ID: 50394
Updated by: jani@php.net
Reported By: tstarling at wikimedia dot org
-Status: Open
+Status: To be documented
-Bug Type: Scripting Engine problem
+Bug Type: Documentation problem
Operating System: Linux
PHP Version: 5.3.1
New Comment:
See bug #49946 and Johannes' comment. This works (in both 5.3 and
5.2):
<?php
function foo( &$x ) {}
class Proxy {
function __call( $name, $args ) {
debug_zval_dump( $args );
$pass = array();
foreach ($args as $arg)
$pass[] =& $arg;
call_user_func_array( 'foo', $pass );
}
}
$arg = 1;
$args = array( &$arg );
$proxy = new Proxy;
call_user_func_array( array( $proxy, 'bar' ), $args );
?>
This really should be documented on the manual at
http://php.net/call_user_func_array
Previous Comments:
------------------------------------------------------------------------
[2009-12-07 01:40:18] tstarling at wikimedia dot org
Description:
------------
This is a regression in the PHP 5.3.1 release. When you call a __call()
function with a reference parameter, it is silently converted to a
value, by the time it reaches the second argument to __call().
This breaks MediaWiki and has no obvious workaround.
Reproduce code:
---------------
function foo( &$x ) {}
class Proxy {
function __call( $name, $args ) {
debug_zval_dump( $args );
call_user_func_array( 'foo', $args );
}
}
$arg = 1;
$args = array( &$arg );
$proxy = new Proxy;
call_user_func_array( array( &$proxy, 'bar' ), $args );
Expected result:
----------------
PHP 5.3.0 produces:
array(1) refcount(4){
[0]=>
&long(1) refcount(5)
}
Actual result:
--------------
array(1) refcount(4){
[0]=>
long(1) refcount(3)
}
Warning: Parameter 1 to foo() expected to be a reference, value given
in /home/tstarling/src/php/stuff/test-reference-call.php on line 8
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50394&edit=1