3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private function foo(&$arg1) { var_dump('arg1: ', $arg1); } } class B extends A { public function bar() { $x = new stdClass(); $x->baz = 'just a value'; $this->callPrivate($x); } private function callPrivate($x) { $method = new \ReflectionMethod( 'A', 'foo' ); //* for some reason, the private function needs to have been changed to be 'accessible' for this to work in 5.4 $method->setAccessible(true); //working 5.4 (* see above) but not in 5.5 $arguments = func_get_args(); //not working in either //$arguments = array($x); // <---- COMMENT THIS LINE TO SEE IT WORK IN PHP 5.4 return $method->invokeArgs($this, $arguments); } } $obj = new B; $obj->bar();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: A::foo(): Argument #1 ($arg1) must be passed by reference, value given in /in/YI5G3 on line 31 string(6) "arg1: " object(stdClass)#2 (1) { ["baz"]=> string(12) "just a value" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.68 ms | 401 KiB | 8 Q