3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface A { public function foo(...$args) : self; } class B implements A { public function foo(...$args) : self { foreach ($args as $arg) { echo $arg."\n"; } } } $x = new B; $x->foo(1, 2, 3);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
1 2 3 Fatal error: Uncaught TypeError: B::foo(): Return value must be of type B, none returned in /in/XbtXf:14 Stack trace: #0 /in/XbtXf(18): B->foo(1, 2, 3) #1 {main} thrown in /in/XbtXf on line 14
Process exited with code 255.
Output for 7.4.0 - 7.4.33
1 2 3 Fatal error: Uncaught TypeError: Return value of B::foo() must be an instance of B, none returned in /in/XbtXf:14 Stack trace: #0 /in/XbtXf(18): B->foo(1, 2, 3) #1 {main} thrown in /in/XbtXf on line 14
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33
Fatal error: Declaration of B::foo(...$args): B must be compatible with A::foo(...$args): A in /in/XbtXf on line 8
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/XbtXf on line 4
Process exited with code 255.
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/XbtXf on line 4
Process exited with code 255.

preferences:
117.16 ms | 411 KiB | 5 Q