3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Garage { public function create():Vehicle; } class CarGarage implements Garage { public function create():Car { return new Car(); } } class Vehicle {} class Car extends Vehicle {} $class = new CarGarage(); var_dump($class->create());
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
object(Car)#2 (0) { }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Fatal error: Declaration of CarGarage::create(): Car must be compatible with Garage::create(): Vehicle in /in/p1m14 on line 6
Process exited with code 255.
Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/p1m14 on line 3
Process exited with code 255.

preferences:
211.32 ms | 403 KiB | 239 Q