3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyIter implements Iterator { private $a; private $key = 0; public function __construct(array $a) { $this->a = array_values($a); } public function key() { return $this->key; } public function rewind() { $this->key = 0; } public function valid() { echo __METHOD__, PHP_EOL; return isset($this->a[$this->key]); } public function next() { echo __METHOD__, PHP_EOL; $this->key++; } public function current() { echo __METHOD__, PHP_EOL; return $this->a[$this->key]; } } $ilist = new MyIter(array('A', 'B', 'C', 'D')); foreach ($ilist as $var) { echo "var = $var\n"; echo "current = ", print_r(current($ilist), true), "\n"; }
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.1.0
MyIter::valid MyIter::current var = A current = Array ( [0] => A [1] => B [2] => C [3] => D ) MyIter::next MyIter::valid MyIter::current var = B current = Array ( [0] => A [1] => B [2] => C [3] => D ) MyIter::next MyIter::valid MyIter::current var = C current = Array ( [0] => A [1] => B [2] => C [3] => D ) MyIter::next MyIter::valid MyIter::current var = D current = Array ( [0] => A [1] => B [2] => C [3] => D ) MyIter::next MyIter::valid
Output for hhvm-3.10.0 - 3.12.0
MyIter::valid MyIter::current var = A current = Warning: Invalid operand type was used: expecting an array in /in/a7NtE on line 45 MyIter::next MyIter::valid MyIter::current var = B current = Warning: Invalid operand type was used: expecting an array in /in/a7NtE on line 45 MyIter::next MyIter::valid MyIter::current var = C current = Warning: Invalid operand type was used: expecting an array in /in/a7NtE on line 45 MyIter::next MyIter::valid MyIter::current var = D current = Warning: Invalid operand type was used: expecting an array in /in/a7NtE on line 45 MyIter::next MyIter::valid
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/a7NtE on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/a7NtE on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/a7NtE on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/a7NtE on line 3
Process exited with code 255.