3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.4.13 - 7.3.0rc6
Output for 5.3.23 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/3qm8h on line 41
Process exited with code 255.