3v4l.org

run code in 500+ PHP versions simultaneously
<?php interface FruitInterface { } interface AppleInterface extends FruitInterface { } class RedApple implements AppleInterface { } interface JuicerInterface { public function addComponent(FruitInterface $fruit); } class CommonJuicer implements JuicerInterface { public function addComponent(FruitInterface $fruit){ } } class SpecialAppleJuicer implements JuicerInterface { public function addComponent(AppleInterface $apple){ } } $redApple = new RedApple(); $juicer = new SpecialAppleJuicer(); $juicer->addComponent($redApple); // Expected that this would not produce Fatal Error, because RedApple implements FruitInterface. // "As of PHP 7.4.0, full covariance and contravariance support was added" // https://www.php.net/manual/en/language.oop5.variance.php
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26
Fatal error: Declaration of SpecialAppleJuicer::addComponent(AppleInterface $apple) must be compatible with JuicerInterface::addComponent(FruitInterface $fruit) in /in/vC0WM on line 31
Process exited with code 255.
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33
Fatal error: Declaration of SpecialAppleJuicer::addComponent(AppleInterface $apple) must be compatible with JuicerInterface::addComponent(FruitInterface $fruit) in /in/vC0WM on line 29
Process exited with code 255.
Output for 8.5.0 - 8.5.11
Fatal error: Declaration of SpecialAppleJuicer::addComponent(AppleInterface $apple) must be compatible with JuicerInterface::addComponent(FruitInterface $fruit) in /in/vC0WM on line 31 Stack trace: #0 {main}
Process exited with code 255.

preferences:
31.86 ms | 1143 KiB | 11 Q