3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class a implements \ArrayAccess, \Iterator, \Countable { private $a; private $b; private $c; private $keys = [ 'a', 'b', 'c' ]; private $pointer; public function __construct($a = null, $b = null, $c = null) { $this->a = $a; $this->b = $b; $this->c = $c; } public function count() { $pointer = 0; foreach ($this as $element) { if ($element) { $pointer++; } } return $pointer; } public function current() { $key = $this->key(); return $this->{$key}; } public function key() { return $this->keys[$this->pointer]; } public function next() { $this->pointer++; } public function valid() { return $this->pointer < count($this->keys) && $this->{$this->keys[$this->pointer]} !== null; } public function rewind() { $this->pointer = 0; } } $me = new a(1,2,3); var_dump($me->count()); foreach ($me as $key => $el) { var_dump($key, $el); } var_dump($me);
based on 0NKU5
Output for 7.0.0 - 7.2.0
Fatal error: Class a contains 4 abstract methods and must therefore be declared abstract or implement the remaining methods (ArrayAccess::offsetExists, ArrayAccess::offsetGet, ArrayAccess::offsetSet, ...) in /in/JkbND on line 4
Process exited with code 255.
Output for 5.4.1 - 5.6.28
Fatal error: Class a contains 4 abstract methods and must therefore be declared abstract or implement the remaining methods (ArrayAccess::offsetExists, ArrayAccess::offsetGet, ArrayAccess::offsetSet, ...) in /in/JkbND on line 62
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/JkbND on line 11
Process exited with code 255.