3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function callStatic($class, $method, $args, $ref, $defined, $called) { var_dump($class, $defined, $called); $ref = new \ReflectionMethod($class, $method); $ref->setAccessible(true); return $ref->invokeArgs(null, array($args)); } class n_0d19ad5d1a89cbbf06a49f56e9dcb11d { public static function foo() { return callStatic('static', 'bar', array(), array(), __CLASS__, call_user_func(function () { set_error_handler(function () { }); $called = get_called_class(); restore_error_handler(); return $called; })); } } class n_1c54f3f5b4e9e0fc521faa21fe127ad8 extends n_0d19ad5d1a89cbbf06a49f56e9dcb11d { protected static function bar() { return __CLASS__; } } echo callStatic('n_1c54f3f5b4e9e0fc521faa21fe127ad8', 'foo', array(), array(), __CLASS__, call_user_func(function () { set_error_handler(function () { }); $called = get_called_class(); restore_error_handler(); return $called; }));
Output for 7.0.0 - 7.1.0
string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" Fatal error: Uncaught ReflectionException: Class static does not exist in /in/8qYIM:5 Stack trace: #0 /in/8qYIM(5): ReflectionMethod->__construct('static', 'bar') #1 /in/8qYIM(21): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_1c54f3f5b4e9e...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/8qYIM(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/8qYIM(38): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Object(ReflectionMethod), '', false) #5 {main} thrown in /in/8qYIM on line 5
Process exited with code 255.
Output for 5.4.30 - 5.6.28
string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" Fatal error: Uncaught exception 'ReflectionException' with message 'Class static does not exist' in /in/8qYIM:5 Stack trace: #0 /in/8qYIM(5): ReflectionMethod->__construct('static', 'bar') #1 /in/8qYIM(21): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_1c54f3f5b4e9e...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/8qYIM(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/8qYIM(38): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/8qYIM on line 5
Process exited with code 255.
Output for 5.4.0 - 5.4.29
string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" Fatal error: Uncaught exception 'ReflectionException' with message 'Class static does not exist' in /in/8qYIM:5 Stack trace: #0 /in/8qYIM(5): ReflectionMethod->__construct('static', 'bar') #1 /in/8qYIM(21): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_0d19ad5d1a89c...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/8qYIM(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/8qYIM(38): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/8qYIM on line 5
Process exited with code 255.
Output for 5.3.2 - 5.3.29
string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" bool(false) Fatal error: Uncaught exception 'ReflectionException' with message 'Class static does not exist' in /in/8qYIM:5 Stack trace: #0 /in/8qYIM(5): ReflectionMethod->__construct('static', 'bar') #1 /in/8qYIM(21): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', false) #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/8qYIM(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/8qYIM(38): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/8qYIM on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.1
string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) Fatal error: Call to undefined method ReflectionMethod::setAccessible() in /in/8qYIM on line 6
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/8qYIM on line 5 Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/8qYIM on line 14
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/8qYIM on line 5 Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/8qYIM on line 14
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/8qYIM on line 5 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8qYIM on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/8qYIM on line 5 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8qYIM on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/8qYIM on line 5 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/8qYIM on line 12
Process exited with code 255.