3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class IncrementIterator implements iterator { protected $start; protected $end; protected $current; public function __construct($start, $end) { $this->start = $start; $this->end = $end; } public function rewind() { $this->current = $this->start; } public function valid() { return $this->current <= $this->end; } public function key() { return $this->current; } public function current() { return $this->current; } public function next() { $this->current++; } } $aIterator = new IncrementIterator(0, 26); $bIterator = new IncrementIterator(0, 26); $cIterator = new IncrementIterator(0, 26); $dIterator = new IncrementIterator(0, 26); $multipleIterator = new MultipleIterator(); $multipleIterator->attachIterator($aIterator); $multipleIterator->attachIterator($bIterator); $multipleIterator->attachIterator($cIterator); $multipleIterator->attachIterator($dIterator); foreach ($multipleIterator as $current) { var_dump($current); }
based on FnWPo
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
array(4) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) } array(4) { [0]=> int(1) [1]=> int(1) [2]=> int(1) [3]=> int(1) } array(4) { [0]=> int(2) [1]=> int(2) [2]=> int(2) [3]=> int(2) } array(4) { [0]=> int(3) [1]=> int(3) [2]=> int(3) [3]=> int(3) } array(4) { [0]=> int(4) [1]=> int(4) [2]=> int(4) [3]=> int(4) } array(4) { [0]=> int(5) [1]=> int(5) [2]=> int(5) [3]=> int(5) } array(4) { [0]=> int(6) [1]=> int(6) [2]=> int(6) [3]=> int(6) } array(4) { [0]=> int(7) [1]=> int(7) [2]=> int(7) [3]=> int(7) } array(4) { [0]=> int(8) [1]=> int(8) [2]=> int(8) [3]=> int(8) } array(4) { [0]=> int(9) [1]=> int(9) [2]=> int(9) [3]=> int(9) } array(4) { [0]=> int(10) [1]=> int(10) [2]=> int(10) [3]=> int(10) } array(4) { [0]=> int(11) [1]=> int(11) [2]=> int(11) [3]=> int(11) } array(4) { [0]=> int(12) [1]=> int(12) [2]=> int(12) [3]=> int(12) } array(4) { [0]=> int(13) [1]=> int(13) [2]=> int(13) [3]=> int(13) } array(4) { [0]=> int(14) [1]=> int(14) [2]=> int(14) [3]=> int(14) } array(4) { [0]=> int(15) [1]=> int(15) [2]=> int(15) [3]=> int(15) } array(4) { [0]=> int(16) [1]=> int(16) [2]=> int(16) [3]=> int(16) } array(4) { [0]=> int(17) [1]=> int(17) [2]=> int(17) [3]=> int(17) } array(4) { [0]=> int(18) [1]=> int(18) [2]=> int(18) [3]=> int(18) } array(4) { [0]=> int(19) [1]=> int(19) [2]=> int(19) [3]=> int(19) } array(4) { [0]=> int(20) [1]=> int(20) [2]=> int(20) [3]=> int(20) } array(4) { [0]=> int(21) [1]=> int(21) [2]=> int(21) [3]=> int(21) } array(4) { [0]=> int(22) [1]=> int(22) [2]=> int(22) [3]=> int(22) } array(4) { [0]=> int(23) [1]=> int(23) [2]=> int(23) [3]=> int(23) } array(4) { [0]=> int(24) [1]=> int(24) [2]=> int(24) [3]=> int(24) } array(4) { [0]=> int(25) [1]=> int(25) [2]=> int(25) [3]=> int(25) } array(4) { [0]=> int(26) [1]=> int(26) [2]=> int(26) [3]=> int(26) }
Output for hhvm-3.10.0 - 3.12.0
Catchable fatal error: Argument 1 passed to MultipleIterator::attachIterator() must implement interface HH\Iterator, IncrementIterator given in /in/TFref on line 39
Process exited with code 255.
Output for 5.0.0 - 5.2.17
Fatal error: Class 'MultipleIterator' not found in /in/TFref on line 38
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/TFref on line 2
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/TFref on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/TFref on line 2
Process exited with code 255.