3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class myIterator implements Iterator { private $position = 0; private $array = array( "firstelement", "secondelement", "lastelement", ); public function __construct() { $this->position = 0; } function rewind() { var_dump(__METHOD__); $this->position = 0; } function current() { var_dump(__METHOD__); return $this->array[$this->position]; } function key() { var_dump(__METHOD__); return $this->position; } function next() { var_dump(__METHOD__); ++$this->position; } function valid() { var_dump(__METHOD__); return isset($this->array[$this->position]); } } $i = new myIterator; foreach ($i as $t) { echo $t; }
Output for 5.1.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
string(18) "myIterator::rewind" string(17) "myIterator::valid" string(19) "myIterator::current" firstelementstring(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" secondelementstring(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" lastelementstring(16) "myIterator::next" string(17) "myIterator::valid"
Output for 5.0.0 - 5.0.5
string(18) "myIterator::rewind" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" firstelementstring(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" secondelementstring(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" lastelementstring(16) "myIterator::next" string(17) "myIterator::valid"
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/v9Qck 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/v9Qck on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/v9Qck on line 3
Process exited with code 255.