3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
l<?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() { var_dump(get_called_class()); 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
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" Fatal error: Uncaught ReflectionException: Class static does not exist in /in/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_1c54f3f5b4e9e...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Object(ReflectionMethod), '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" Fatal error: Uncaught exception 'ReflectionException' with message 'Method static::bar() does not exist' in /in/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct() #1 /in/NPJ8p(22): callStatic() #2 (): n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo() #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs() #4 /in/NPJ8p(39): callStatic() #5 {main}
Process exited with code 255.
Output for 5.4.30 - 5.6.28
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" 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/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_1c54f3f5b4e9e...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for 5.4.1 - 5.4.29
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" 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/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_0d19ad5d1a89c...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for 5.4.0
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" 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/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', 'n_0d19ad5d1a89c...') #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for 5.3.11 - 5.3.29
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" bool(false) Fatal error: Uncaught exception 'ReflectionException' with message 'Class static does not exist' in /in/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', false) #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for 5.3.2 - 5.3.10
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" string(6) "static" string(34) "n_0d19ad5d1a89cbbf06a49f56e9dcb11d" bool(false) Fatal error: Uncaught exception 'ReflectionException' with message 'Class static does not exist' in /in/NPJ8p:5 Stack trace: #0 /in/NPJ8p(5): ReflectionMethod->__construct('static', 'bar') #1 /in/NPJ8p(22): callStatic('static', 'bar', Array, Array, 'n_0d19ad5d1a89c...', false) #2 [internal function]: n_0d19ad5d1a89cbbf06a49f56e9dcb11d::foo(Array) #3 /in/NPJ8p(7): ReflectionMethod->invokeArgs(NULL, Array) #4 /in/NPJ8p(39): callStatic('n_1c54f3f5b4e9e...', 'foo', Array, Array, '', false) #5 {main} thrown in /in/NPJ8p on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.1
lstring(34) "n_1c54f3f5b4e9e0fc521faa21fe127ad8" string(0) "" bool(false) Fatal error: Call to undefined method ReflectionMethod::setAccessible() in /in/NPJ8p 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/NPJ8p on line 5 Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/NPJ8p on line 15
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NPJ8p on line 5 Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/NPJ8p on line 15
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NPJ8p on line 5 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NPJ8p 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/NPJ8p on line 5 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NPJ8p 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/NPJ8p on line 5 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NPJ8p on line 12
Process exited with code 255.