3v4l.org

run code in 300+ PHP versions simultaneously
<?php (function() { $iterator = $this->getIterator(); foreach ($iterator as $value) { var_dump($value); } var_dump($iterator->getReturn()); })->call(new class implements IteratorAggregate { public function getIterator() { yield 0; yield from [1,2,3,4]; return 5; } });
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Return type of IteratorAggregate@anonymous::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IgsiV on line 10 int(0) int(1) int(2) int(3) int(4) int(5)
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
int(0) int(1) int(2) int(3) int(4) int(5)
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /in/IgsiV on line 9
Process exited with code 255.

preferences:
266.68 ms | 402 KiB | 369 Q