3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class a implements \Iterator, \Countable { private $a; private $b; private $c; private $keys = [ 'a', 'b', 'c' ]; private $pointer; public function __construc($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(); var_dump($key); return $this->{$key}; } public function key() { $this->keys[$this->pointer]; } public function next() { $this->pointer++; } public function valid() { return $this->pointer < count($this->keys); } public function rewind() { $this->pointer = 0; } } $me = new a('a'); var_dump($me->count()); foreach ($me as $key => $el) { var_dump($key, $el); }
based on jEEBM
Output for 7.1.0 - 7.2.0
NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 int(0) NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 NULL NULL NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 NULL NULL NULL Notice: Undefined property: a::$ in /in/hkarD on line 41 NULL NULL
Output for 7.0.0 - 7.0.20
NULL Fatal error: Uncaught Error: Cannot access empty property in /in/hkarD:41 Stack trace: #0 /in/hkarD(28): a->current() #1 /in/hkarD(67): a->count() #2 {main} thrown in /in/hkarD on line 41
Process exited with code 255.
Output for 5.4.1 - 5.6.28
NULL Fatal error: Cannot access empty property in /in/hkarD on line 41
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hkarD on line 11
Process exited with code 255.