3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
Fatal error: Uncaught Exception in /in/s8ti7:7 Stack trace: #0 /in/s8ti7(5): {closure}('Foointerface') #1 /in/s8ti7(17): {closure}('Foo') #2 {main} thrown in /in/s8ti7 on line 7
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Exception in /in/s8ti7:7 Stack trace: #0 [internal function]: {closure}('Foointerface') #1 /in/s8ti7(5): spl_autoload_call('Foointerface') #2 [internal function]: {closure}('Foo') #3 /in/s8ti7(17): spl_autoload_call('Foo') #4 {main} thrown in /in/s8ti7 on line 7
Process exited with code 255.
Output for 5.6.38 - 5.6.40, 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.19, 7.2.21 - 7.2.33, 7.3.0 - 7.3.6, 7.3.8 - 7.3.33
object(Foo)#3 (0) { } bool(false) array(0) { }
Output for 7.2.20, 7.3.7
Fatal error: During class fetch: Uncaught Exception in /in/s8ti7:7 Stack trace: #0 [internal function]: {closure}('Foointerface') #1 /in/s8ti7(5): spl_autoload_call('Foointerface') #2 [internal function]: {closure}('Foo') #3 /in/s8ti7(13): spl_autoload_call('Foo') #4 {main} in /in/s8ti7 on line 5
Process exited with code 255.

preferences:
193.78 ms | 402 KiB | 221 Q