3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface testInterface { public function doAction(); } class Foo implements testInterface { public function doAction() { echo "Action!"; } } class Bar { protected $test = "test"; } class Baz { public function __construct(testInterface $class) { echo "Everything's ok!"; } } $foo = new Foo(); $bar = new Bar(); $baz = new Baz($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.6
Fatal error: Uncaught TypeError: Baz::__construct(): Argument #1 ($class) must be of type testInterface, Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD:23 Stack trace: #0 /in/vilbD(31): Baz->__construct(Object(Bar)) #1 {main} thrown in /in/vilbD on line 23
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to Baz::__construct() must implement interface testInterface, instance of Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD:23 Stack trace: #0 /in/vilbD(31): Baz->__construct(Object(Bar)) #1 {main} thrown in /in/vilbD on line 23
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Catchable fatal error: Argument 1 passed to Baz::__construct() must implement interface testInterface, instance of Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD on line 23
Process exited with code 255.

preferences:
212.08 ms | 402 KiB | 227 Q