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();

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Arrow functions
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 Object typehint
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.

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page