I am trying to return a value from a method as a reference in PHP5.3. I may be mistaken in this, but I am bringing an older project to speed up work with some of the newer 5.3+ features.
Below is an example that I whipped to explain what was going on:
class Foo { static $foobar = 5; function &bar() { return self::$foobar; } } // Doesn't work //$test1 = &call_user_func_array(array("Foo","bar"),array()); // Doesn't work //$test1 = &call_user_func_array("Foo::bar",array()); // Doesn't work //$f = new Foo; $test1 = &call_user_func_array(array($f,"bar"),array()); // WORKS //$test1 = &Foo::bar(); //Doesn't work //$function = "Foo::bar"; //$test1 = &$function(); // WORKS $f = new Foo; $test1 = &$f->bar(); $test2 = Foo::bar(); var_dump($test1); var_dump($test2); $test1 = 10; echo "----------<br />"; var_dump($test1); var_dump($test2); var_dump(Foo::bar()); //returns 10 when working, 5 when not working
The very latest Foo::bar() should return 10, since $test1 should be a reference to Foo::$foobar when everything works.
I understand that this example also uses some funky legacy PHP call Foo::bar , and the bar() method is not set as static, but can still be called via ::
Any help would be greatly appreciated since the only fix I have so far is simply setting switch in the argument list and calling the method directly based on how many arguments exist.
source share