3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface WorldInterface { function doAThing($foo); } class World implements WorldInterface { public function __construct(string $name) { $this->name = $name; } public function doAThing($foo) { echo $foo; } } class BackwardsWorld implements WorldInterface { public function __construct(string $name) { $this->name = strrev($name); } public function doAThing($foo) { echo strrev($foo); } } class Hello { /** * @var World */ private $world; public function setWorld( WorldInterface $world ) { $this->world = $world; } } class WorldFactory { // full disclosure: I'm still bad at factories public static function makeWorld($name) { return new World($name); } public static function makeDlrow($name) { return new BackwardsWorld($name); } } $hey = new Hello(); $hey->setWorld(WorldFactory::makeWorld('blorp')); $yeh = new Hello(); $yeh->setWorld(WorldFactory::makeDlrow('blorp')); var_dump($hey, $yeh);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property World::$name is deprecated in /in/cK3Wo on line 9 Deprecated: Creation of dynamic property BackwardsWorld::$name is deprecated in /in/cK3Wo on line 19 object(Hello)#1 (1) { ["world":"Hello":private]=> object(World)#2 (1) { ["name"]=> string(5) "blorp" } } object(Hello)#3 (1) { ["world":"Hello":private]=> object(BackwardsWorld)#4 (1) { ["name"]=> string(5) "prolb" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

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


preferences:
58.93 ms | 402 KiB | 8 Q