3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class States implements \ArrayAccess { private $states = []; /** * @param mixed $offset * * @return bool */ public function offsetExists($offset) { return array_key_exists($offset, $this->states); } /** * @param mixed $offset * * @throws UnknownStateException * * @return AllianceState */ public function offsetGet($offset) { if ( ! $this->offsetExists($offset)) { throw new UnknownStateException(); } return $this->states[$offset]; } /** * @param mixed $offset * @param mixed $value * * @throws InvalidArgumentException */ public function offsetSet($offset, $value) { $offset = count($this->states); $this->states[$offset] = $value; } /** * @param mixed $offset * * @throws UnknownStateException */ public function offsetUnset($offset) { unset($this->states[$offset]); $this->states = array_values($this->states); } } $states = new States(); $states->add('foo'); $states->add('bar'); var_dump($states);
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method States::add() in /in/b89Xl:62 Stack trace: #0 {main} thrown in /in/b89Xl on line 62
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Call to undefined method States::add() in /in/b89Xl on line 62
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/b89Xl on line 6
Process exited with code 255.