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

 ID:                 40694
 Comment by:         dan dot lugg at gmail dot com
 Reported by:        and...@php.net
 Summary:            __call() does not allow passing args by reference
 Status:             No Feedback
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 PHP Version:        5CVS-2007-03-02 (CVS)
 Block user comment: N
 Private report:     N

 New Comment:

Has this issue received any attention? I've noticed it cropping up
elsewhere in the bug database. An example of where it is failing still:



    class TestClass{

        public static function __callStatic($function, $arguments){

            return call_user_func_array($function, $arguments);

        }

    }



    function testFunction(&$arg){

        $arg .= 'bar';

    }



    $test = 'foo';

    TestClass::testFunction($test);

    echo $test;



----



Expected result:

    string(6) "foobar"



----



Actual result:

    Warning: Parameter 1 to testFunction() expected to be a reference,
value given in ...

    string(3) "foo"



----



By passing the argument by reference at call time, it succeeds:



    TestClass::testFunction(&$test);



Result:

    string(6) "foobar"



However, this of course begins issuing deprecation warnings in my IDE
regarding the call-time passing-by-reference.



----



Any progress?


Previous Comments:
------------------------------------------------------------------------
[2007-09-15 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------
[2007-09-07 21:07:50] tony2...@php.net

I don't see how it is possible without forcing the reference OR having a
method like __callByRef(), which makes little sense to me.

------------------------------------------------------------------------
[2007-09-04 19:59:54] and...@php.net

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

------------------------------------------------------------------------
[2007-08-31 12:13:24] tony2...@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] poll...@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()...

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


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

    http://bugs.php.net/bug.php?id=40694


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

Reply via email to