3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar{} class Baz{} class Foo { public function __construct(Bar ...$bars) { var_dump($bars); } } $foo = new Foo(...[new Bar, new Bar]); $foo = new Foo(...[new Bar, new Bar, new Baz]);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(2) { [0]=> object(Bar)#2 (0) { } [1]=> object(Bar)#3 (0) { } } Fatal error: Uncaught TypeError: Foo::__construct(): Argument #3 must be of type Bar, Baz given, called in /in/SDRZ0 on line 16 and defined in /in/SDRZ0:9 Stack trace: #0 /in/SDRZ0(16): Foo->__construct(Object(Bar), Object(Bar), Object(Baz)) #1 {main} thrown in /in/SDRZ0 on line 9
Process exited with code 255.
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
array(2) { [0]=> object(Bar)#2 (0) { } [1]=> object(Bar)#3 (0) { } } Fatal error: Uncaught TypeError: Argument 3 passed to Foo::__construct() must be an instance of Bar, instance of Baz given, called in /in/SDRZ0 on line 16 and defined in /in/SDRZ0:9 Stack trace: #0 /in/SDRZ0(16): Foo->__construct(Object(Bar), Object(Bar), Object(Baz)) #1 {main} thrown in /in/SDRZ0 on line 9
Process exited with code 255.

preferences:
107.1 ms | 1724 KiB | 4 Q