|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-02 17:27 UTC] 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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 01:00:01 2025 UTC |
<?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.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?