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 8.1.0 - 8.1.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
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
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30

preferences:
229.15 ms | 404 KiB | 337 Q