3v4l.org

run code in 200+ PHP versions simultaneously
<?php interface IService { public function interfaceFunction(); } final class ServiceWithOtherFunction implements IService { public function interfaceFunction() { echo "ServiceWithOtherFunction interfaceFunction\n"; } public function otherFunction() { echo "ServiceWithOtherFunction otherFunction\n"; } } final class Controller { private $service; public function __construct(IService $service) { $this->service = $service; } public function indexAction() { $this->service->interfaceFunction(); $this->service->otherFunction(); } } $controllerWithOtherFunction = new Controller(new ServiceWithOtherFunction); $controllerWithOtherFunction->indexAction(); final class ServiceWithoutOtherFunction implements IService { public function interfaceFunction() { echo "ServiceWithoutOtherFunction interfaceFunction\n"; } } $controllerWithoutOtherFunction = new Controller(new ServiceWithoutOtherFunction); $controllerWithoutOtherFunction->indexAction();
Output for 7.0.0 - 7.4.0
ServiceWithOtherFunction interfaceFunction ServiceWithOtherFunction otherFunction ServiceWithoutOtherFunction interfaceFunction Fatal error: Uncaught Error: Call to undefined method ServiceWithoutOtherFunction::otherFunction() in /in/mZcRq:28 Stack trace: #0 /in/mZcRq(43): Controller->indexAction() #1 {main} thrown in /in/mZcRq on line 28
Process exited with code 255.
Output for 5.6.0 - 5.6.30
ServiceWithOtherFunction interfaceFunction ServiceWithOtherFunction otherFunction ServiceWithoutOtherFunction interfaceFunction Fatal error: Call to undefined method ServiceWithoutOtherFunction::otherFunction() in /in/mZcRq on line 28
Process exited with code 255.