3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface bird { function setKind(string $type); function getKind(); function getLocation(); function setLocation(location $location); function flyTo(location $location); function setMelody(string $melody); function singMelody(); function killBird(); function cloneBird(int $count); } abstract class location{ private $x; private $y; private $z; } class Position extends location { private $x; private $y; private $z; function set(int $x, int $y, int $z) { $this->x = $x; $this->y = $y; $this->z = $z; } function get() { return [ $this->x, $this->y, $this->z ]; } function __construct(int $x, int $y, int $z) { $this->set($x,$y,$z); } } class BirdFactory implements Iterator { private $position = 0; private $count; private $object; function __construct(int $count, bird $object) { $this->count = $count; $this->object = $object; } function rewind() { $this->position = 0; } function current() { return clone $this->object; } function key() { return $this->position; } function next() { ++$this->position; } function valid() { return $this->position < $this->count; } } abstract class AbstractBird implements bird { private $kind; private $location; private $melody; private $isAlive = true; function __construct() { $this->setLocation(new Position(0, 0, 0)); } function setKind(string $type) { $this->kind = $type; } function getKind() { return $this->kind; } function setLocation(location $location) { $this->location = $location; } function getLocation() { return $this->location; } function flyTo(location $location) { $this->location = $location; } function setMelody(string $melody) { $this->melody = $melody; } function singMelody() { return $this->melody; } function killBird() { return $this->isAlive = false; } function cloneBird(int $count){ return new BirdFactory($count, $this); } } class Duck extends AbstractBird { function __construct() { parent::__construct(); $this->setKind('Duck'); $this->setMelody('Quack! Quack!'); } } class Crow extends AbstractBird { function __construct() { parent::__construct(); $this->setKind('Crow'); $this->setMelody('Caw! Caw!'); } } class Penguin extends AbstractBird { function __construct() { parent::__construct(); $this->setKind('Penguin'); $this->setMelody('Ping! Ping!'); } function flyTo(location $location) { throw new Exception('Sorry, Penguins can\'t fly :('); } }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of BirdFactory::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3qm8h on line 70 Deprecated: Return type of BirdFactory::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3qm8h on line 78 Deprecated: Return type of BirdFactory::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3qm8h on line 74 Deprecated: Return type of BirdFactory::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3qm8h on line 82 Deprecated: Return type of BirdFactory::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3qm8h on line 66

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:
57.11 ms | 403 KiB | 8 Q