3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class ColumnFieldsIterator implements \IteratorAggregate { public function getIterator() { return new \ArrayIterator(['columns2','columns']); } } class RowFieldsIterator implements \IteratorAggregate { public function getIterator() { return new \ArrayIterator(['rows2','rows']); } } class AllIterator implements \IteratorAggregate { public function getIterator() { $multipleIterator = new MultipleIterator; $multipleIterator->attachIterator(new ColumnFieldsIterator); $multipleIterator->attachIterator(new RowFieldsIterator); return $multipleIterator; } } $all = new AllIterator; foreach ($all as $k => $v) { echo "$k => $v\n"; }
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to MultipleIterator::attachIterator() must implement interface Iterator, instance of ColumnFieldsIterator given in /in/YJqEe:24 Stack trace: #0 /in/YJqEe(24): MultipleIterator->attachIterator(Object(ColumnFieldsIterator)) #1 /in/YJqEe(32): AllIterator->getIterator() #2 {main} thrown in /in/YJqEe on line 24
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Catchable fatal error: Argument 1 passed to MultipleIterator::attachIterator() must implement interface Iterator, instance of ColumnFieldsIterator given in /in/YJqEe on line 24
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/YJqEe on line 7
Process exited with code 255.