3v4l.org

run code in 300+ PHP versions simultaneously
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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
l Fatal error: Uncaught Error: get_called_class() must be called from within a class in /in/NPJ8p:36 Stack trace: #0 /in/NPJ8p(39): {closure}() #1 {main} thrown in /in/NPJ8p on line 36
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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 5.4.30 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
243.2 ms | 401 KiB | 329 Q