3v4l.org

run code in 300+ PHP versions simultaneously
<?php function userland_call_user_func($function, ...$args) { if (! is_array($function)) { return $function(...$args); } $object = reset($function); if (is_object($object)) { return Closure::bind(function () use ($args, $function) { return $function(...$args); }, $object, get_class($object))->__invoke(); } return $function(...$args); } class Test1 { private function foo() { echo new Exception; } public function callFoo($callfunc) { $new=new Test2; $callfunc(array($new, 'foo')); } } class Test2 { private function foo() { echo new Exception; } } $o = new Test1; $o->callFoo('userland_call_user_func'); $o->callFoo('call_user_func');
Output for git.master, git.master_jit, rfc.property-hooks
Exception in /in/rgmh8:24 Stack trace: #0 /in/rgmh8(12): Test2->foo() #1 /in/rgmh8(13): Test2->{closure}() #2 /in/rgmh8(13): Closure->__invoke() #3 /in/rgmh8(21): userland_call_user_func(Array) #4 /in/rgmh8(29): Test1->callFoo('userland_call_u...') #5 {main} Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, cannot access private method Test2::foo() in /in/rgmh8:21 Stack trace: #0 /in/rgmh8(21): call_user_func(Array) #1 /in/rgmh8(30): Test1->callFoo('call_user_func') #2 {main} thrown in /in/rgmh8 on line 21
Process exited with code 255.

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:
32.76 ms | 402 KiB | 8 Q