Bug #50394 [Com]: Reference argument converted to value in __call

From: Date: Mon, 10 Mar 2014 05:56:55 +0000
Subject: Bug #50394 [Com]: Reference argument converted to value in __call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184678@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50394&edit=1

 ID:                 50394
 Comment by:         tstarling@php.net
 Reported by:        tstarling at wikimedia dot org
 Summary:            Reference argument converted to value in __call
 Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        5.3.1
 Assigned To:        pajoye
 Block user comment: N
 Private report:     N

 New Comment:

dessander: that is unrelated
bgardner: that is also unrelated

Both test cases are covered by my comment from 2010-09-15. In bgardner's test case, both the
elements of $args and the elements of $newargs are made into references by the reference assignment,
so it doesn't matter which one you pass. Putting a space between "=" and
"&" is misleading, since "=&" is a binary operator which binds two
variables. The "&" is not an address-of operator.

File a separate bug if you want to complain about unrelated behaviour.


Previous Comments:
------------------------------------------------------------------------
[2014-03-10 05:05:56] bgardner at noggin dot com dot au

And 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');

?>

------------------------------------------------------------------------
[2013-06-12 11:54:24] merzikain at yahoo dot com

Still a bug with 5.4.16 as well.

------------------------------------------------------------------------
[2013-05-08 14:55:35] dessander at gmail dot com

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
NULL

------------------------------------------------------------------------
[2010-10-22 07:58:58] john dot GTD at yahoo dot com

What are the exact steps to reproduce the problem?

I'm running MediaWiki on UniformServer with PHP 5.3.3 and didn't have any problems 
yet.

------------------------------------------------------------------------
[2010-10-11 04:18:58] master33rd at yahoo dot com

I find it disturbing that the bug has been declared fixed, when it hasn't.

Starting Mediawiki with Xampp (even with the new beta of XAMPP)...the same error occurs.  "PHP
5.3.1 is not compatible with MediaWiki due to a bug involving reference parameters to __call.
Upgrade to PHP 5.3.2 or higher, or downgrade to PHP 5.3.0 to fix this. ABORTING (see http://bugs.php.net/bug.php?id=50394 for
details)"  Upgrading to PhP 5.3.3 doesn't fix the problem.  

Let's stop passing the buck and fix this.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=50394


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=50394&edit=1


Thread (29 messages)

« previous php.bugs (#184678) next »