3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * @template TKey * @template TValue * @implements IteratorAggregate<TKey, TValue> */ final class RewindableGenerator implements IteratorAggregate { /** * @param callable(): Generator<TKey, TValue> $generatorFunction */ public function __construct(private $generatorFunction) {} public function getIterator(): Traversable { return ($this->generatorFunction)(); } } /** * @return Generator<int, int> */ function thousand(): Generator { for ($i = 0; $i < 1000; ++$i) { yield $i; } } $thousand = new RewindableGenerator(thousand(...)); foreach ($thousand as $i); foreach ($thousand as $i); foreach ($thousand as $i);
Output for 8.1.0 - 8.1.13, 8.2rc1 - rc3
Output for 8.0.1 - 8.0.25
Parse error: syntax error, unexpected token ")" in /in/46Evq on line 33
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE) in /in/46Evq on line 15
Process exited with code 255.

preferences:
18.53 ms | 411 KiB | 5 Q