3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { private static function bar($t) { var_dump ($t);} } $ref= (new ReflectionMethod('ReflectionMethod', 'invokeArgs')); $closure = function () use ($ref) { var_dump(get_called_class()); $ref->invokeArgs(new ReflectionMethod('Foo', 'bar'), [null,[2]]); }; $closure = $closure->bindTo(null, 'Foo'); $closure();
based on AaH34
Output for 7.0.0 - 7.1.0
string(3) "Foo" Fatal error: Uncaught ReflectionException: Trying to invoke private method Foo::bar() from scope ReflectionMethod in /in/KHom6:11 Stack trace: #0 [internal function]: ReflectionMethod->invokeArgs(NULL, Array) #1 /in/KHom6(11): ReflectionMethod->invokeArgs(Object(ReflectionMethod), Array) #2 /in/KHom6(14): Foo::{closure}() #3 {main} thrown in /in/KHom6 on line 11
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
string(3) "Foo" int(2)
Output for 5.4.0 - 5.6.28
string(3) "Foo" Fatal error: Uncaught exception 'ReflectionException' with message 'Trying to invoke private method Foo::bar() from scope ReflectionMethod' in /in/KHom6:11 Stack trace: #0 [internal function]: ReflectionMethod->invokeArgs(NULL, Array) #1 /in/KHom6(11): ReflectionMethod->invokeArgs(Object(ReflectionMethod), Array) #2 /in/KHom6(14): Foo::{closure}() #3 {main} thrown in /in/KHom6 on line 11
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/KHom6 on line 11
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/KHom6 on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/KHom6 on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/KHom6 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/KHom6 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/KHom6 on line 5
Process exited with code 255.