3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php spl_autoload_register(function ($class) { if ('Foo' === $class) { class Foo implements Foointerface {} } elseif ('Foointerface' === $class) { throw new Exception(); } }); try { // First call triggers the autoloader new Foo(); } catch (Exception $e) {} // For the second call Foo is loaded var_dump(new Foo()); // Even though it’s missing the interface var_dump(new Foo() instanceof Foointerface); var_dump((new ReflectionClass('Foo'))->getInterfaces());
Output for 5.4.0 - 5.6.38, 7.0.0 - 7.3.0rc2
object(Foo)#3 (0) { } bool(false) array(0) { }
Output for hhvm-3.22.0
Fatal error: Uncaught exception 'Exception' with message '' in /in/s8ti7:-1 Stack trace: #0 /in/s8ti7(-1): Closure$() #1 /in/s8ti7(-1): Closure$() #2 {main}
Process exited with code 255.
Output for hhvm-3.10.1 - 3.21.3
Fatal error: Uncaught exception 'Exception' with message '' in /in/s8ti7:7 Stack trace: #0 /in/s8ti7(5): Closure$() #1 /in/s8ti7(17): Closure$() #2 {main}
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/s8ti7 on line 21
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/s8ti7 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/s8ti7 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/s8ti7 on line 3
Process exited with code 255.