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() { $iterator = new AppendIterator; $iterator->append(new ColumnFieldsIterator); $iterator->append(new RowFieldsIterator); return $iterator ; } } $all = new AllIterator; foreach ($all as $k => $v) { echo "$k => $v\n"; }
based on YJqEe
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to AppendIterator::append() must implement interface Iterator, instance of ColumnFieldsIterator given in /in/qbDrX:24 Stack trace: #0 /in/qbDrX(24): AppendIterator->append(Object(ColumnFieldsIterator)) #1 /in/qbDrX(32): AllIterator->getIterator() #2 {main} thrown in /in/qbDrX on line 24
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Catchable fatal error: Argument 1 passed to AppendIterator::append() must implement interface Iterator, instance of ColumnFieldsIterator given in /in/qbDrX on line 24
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/qbDrX on line 7
Process exited with code 255.