3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Collection implements Iterator { protected $array, $valid = false; public function __construct(array $a) { echo __METHOD__ . "\n"; $this->array = $a; } public function current() { echo __METHOD__ . "\n"; return current($this->array); } public function key() { echo __METHOD__ . "\n"; return key($this->array); } public function next() { echo __METHOD__ . "\n"; $this->valid = (false !== next($this->array)); } public function valid() { echo __METHOD__ . "\n"; return $this->valid; } public function rewind() { echo __METHOD__ . "\n"; $this->valid = (false !== reset($this->array)); } } class TestFilter extends FilterIterator { public function accept() { echo __METHOD__ . "\n"; #throw new Exception("Failure in Accept"); } } $test = new TestFilter(new Collection(array(0))); try { foreach ($test as $item) { echo $item; } } catch (Exception $e) { var_dump($e->getMessage()); } ?> ===DONE===
based on jLMCn
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.1.0
Collection::__construct Collection::rewind Collection::valid Collection::current Collection::key TestFilter::accept Collection::next Collection::valid ===DONE===
Output for hhvm-3.10.0 - 3.12.0
Collection::__construct Collection::rewind Collection::valid TestFilter::accept Collection::next Collection::valid Collection::valid ===DONE===
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/8JaC8 on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/8JaC8 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/8JaC8 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/8JaC8 on line 3
Process exited with code 255.