3v4l.org

run code in 300+ PHP versions simultaneously
<?php function makeGen(array $array = []): Generator { $item = current($array); yield $item; while($item = next($array)) { yield $item; } } class GeneratorIterator implements \Iterator { private $genMaker; private $genArg; private $current; public function __construct(callable $genMaker, $arg) { $this->genMaker = $genMaker; $this->genArg = $arg; $this->current = $genMaker($arg); } public function current() { return $this->current->current(); } public function key() { return $this->current->key(); } public function rewind() { $this->current = call_user_func($this->genMaker, $this->genArg); } public function valid() { return $this->current->valid(); } public function next() { $this->current->next(); } } $genIterator = new GeneratorIterator('makeGen', [1,2,3]); foreach($genIterator as $key => $value) { echo $key . ' -> ' . $value . "\n"; } echo "\n"; foreach($genIterator as $key => $value) { echo $key . ' -> ' . $value . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of GeneratorIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/QOEAs on line 26 Deprecated: Return type of GeneratorIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/QOEAs on line 46 Deprecated: Return type of GeneratorIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/QOEAs on line 31 Deprecated: Return type of GeneratorIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/QOEAs on line 41 Deprecated: Return type of GeneratorIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/QOEAs on line 36 0 -> 1 1 -> 2 2 -> 3 0 -> 1 1 -> 2 2 -> 3

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
124.07 ms | 409 KiB | 5 Q