#40694 [Fbk]: __call() does not allow passing args by reference

From: Date: Tue, 04 Sep 2007 19:59:55 +0000
Subject: #40694 [Fbk]: __call() does not allow passing args by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-117125@lists.php.net to get a copy of this message
 ID:          40694
 Updated by:  andrei@php.net
 Reported By: andrei@php.net
 Status:      Feedback
 Bug Type:    Scripting Engine problem
 PHP Version: 5CVS-2007-03-02 (CVS)
 New Comment:

You're forcing a call-time reference. How is this going to help when
call-time reference stuff is deprecated?


Previous Comments:
------------------------------------------------------------------------

[2007-08-31 12:13:24] tony2001@php.net

<?php 
class Foo {
    function __call($method, $args) //NB 1
    {
        print $args[0]."\n";
        $args[0] = 5;
        print $args[0]."\n";
        return true;
    }
}

$v = 'str';

$o = new Foo();
$o->test(&$v); //NB 2 

var_dump($v);
?>

This code results in:
str
5
int(5)

So I believe this report can be closed.

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

[2007-03-02 17:51:47] pollita@php.net

Summary from IRC:

This should be fixable by selectively populating arg_info in
zend_std_get_method() with a structure that turns on the pass rest by
ref flag.   That'll tell the macros in zend_vm_def.h to send the
arguments by reference.  From there, you might need to modify
zend_std_call_user_call() a little bit where it's building the args
array... (Havn't looked close enough to be sure)

While addressing this, you should look at the return value as well,
again this should be a minor matter of checking the __call
implementation and flipping the return type in zend_std_get_method()...

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

[2007-03-02 17:27:59] andrei@php.net

Description:
------------
__call() method does not allow specifying the arguments array by
reference. Essentially this means that there is no way to return
modified arguments when using overloading.

Reproduce code:
---------------
class Foo {
    function __call($method, &$args)
    {
        print $args[0]."\n";
        $args[0] = 5;
        print $args[0]."\n";
        return true;
    }
}

$v = 'str';

$o = new Foo();
$o->test($v);

var_dump($v);


Expected result:
----------------
str
5
int(5)


Actual result:
--------------
str
5
string(3) "str"



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


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


Thread (6 messages)

« previous php.bugs (#117125) next »