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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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:
160.75 ms | 402 KiB | 217 Q