3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Feature { public function getClass() { $func = function (self $instance) { print get_class($instance); }; $func($this); } } class Foo { use Feature; } class Bar { use Feature; } (new Foo)->getClass(); (new Bar)->getClass();
Output for 7.1.20 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 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
FooBar
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 FooBar
Output for 7.1.0 - 7.1.13, 7.2.0 - 7.2.1
Foo Fatal error: Uncaught TypeError: Argument 1 passed to Bar::{closure}() must be an instance of Foo, instance of Bar given, called in /in/oKeSG on line 10 and defined in /in/oKeSG:6 Stack trace: #0 /in/oKeSG(10): Bar->{closure}(Object(Bar)) #1 /in/oKeSG(26): Bar->getClass() #2 {main} thrown in /in/oKeSG on line 6
Process exited with code 255.

preferences:
197.11 ms | 402 KiB | 187 Q