|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-12-07 01:40 UTC] 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
PatchesMediaWiki (last revision 2010-09-10 14:51 UTC by produzione at solarisenergy dot it)chihanglow (last revision 2010-07-09 00:10 UTC by chihanglow at gmail dot com) Php_Patch (last revision 2010-05-18 08:00 UTC by saschasteffens at gmx dot net) sedwdfqf (last revision 2010-03-31 16:40 UTC by www dot mhobkirk at shaw dot ca) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 11:00:01 2025 UTC |
install-utils.inc set comments /* $test = new PhpRefCallBugTester; $test->execute(); if ( !$test->ok ) { echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" . "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" . "downgrade to PHP 5.3.0 to fix this.\n" . "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n"; die( -1 ); } */Commenters please note: you're receiving an error "parameter expected to be a reference, value given", that does not mean that you are seeing this bug. In fact, if you're using PHP 5.3.2 or later, it is pretty much impossible for it to be this bug. Most cases of "parameter expected to be a reference, value given" are due to bugs in the user code, not due to any problem with PHP. The message indicates a mismatch between the reference/value status of arguments to call_user_func_array() and the function declaration, as in: function foo( &$x ) {} $x = ''; call_user_func_array( 'foo', array( $x ) ); The correct way to call the function foo() in this case is: call_user_func_array( 'foo', array( &$x ) ); That is to say, the reference must be explicit in the array on the calling side.Still active bug. My PHP Version: PHP 5.4.14 (cli) (built: Apr 11 2013 19:13:00) Code to reproduce: <?php class TestForCall { public static function myFunc($test, &$reference_var) { var_dump($test); $reference_var = 'changed'; } } class Test { public function __call($name, $arguments) { return call_user_func_array( array( 'TestForCall', 'myFunc' ), $arguments ); } } (new Test()) ->notExistsFunction('test', $reference_var) ; var_dump($reference_var); Output: PHP Warning: Parameter 2 to TestForCall::myFunc() expected to be a reference, value given in /www/godudu.local/test.php on line 22 Warning: Parameter 2 to TestForCall::myFunc() expected to be a reference, value given in /www/godudu.local/test.php on line 22 NULLAnd a test case that shows the weirdness. Run against PHP 5.3.3 <?php function foo($a,&$b){ print $a . ' ' . $b . "\n"; } function fails(){ $args = func_get_args(); call_user_func_array('foo',$args); } function works(){ $args = func_get_args(); $newargs = array(); foreach (array_keys($args) as $k){ $newargs[$k] = &$args[$k]; } //Notice here that I do not pass in $newargs, but $args call_user_func_array('foo',$args); } works('Hello','World'); fails('Hello','World'); ?>