3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_error_handler( function ($code, $string) { throw new Exception($string, $code); } ); try { interface I1 {} interface I2 {} class A implements I1 { public function fn() { echo 'foo'; } } class B extends A implements I2 { public function fn($arg) { echo $arg; } } } catch (Exception $e) { // ignore } $b = new B(); var_dump($b instanceof I1); // outputs "bool(false)" var_dump($b instanceof I2); // outputs "bool(false)" var_dump(class_implements('B')); // outputs "array(1) { 'I1' => string(2) "I1" }" $b->fn('bar'); // outputs "bar"
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
Fatal error: Declaration of B::fn($arg) must be compatible with A::fn() in /in/fkbOC on line 13
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: Declaration of B::fn($arg) must be compatible with A::fn() in /in/fkbOC on line 13
Process exited with code 255.
Output for 7.4.0 - 7.4.33
bool(true) bool(true) array(2) { ["I1"]=> string(2) "I1" ["I2"]=> string(2) "I2" } bar
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
bool(true) bool(false) array(1) { ["I1"]=> string(2) "I1" } bar

preferences:
156.53 ms | 402 KiB | 182 Q