3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements Iterator { public function rewind(){ echo "rewind\n"; } private $c = 0; public function valid(){ return $this->c++ < 5; } public function next(){} public function key(){ return $this->c; } public function current(){ return $this->c; } } $gen = (function(){ $foo = new Foo(); $foo->rewind(); $foo->valid(); yield $foo->key() => $foo->current(); $foo->next(); $foo->valid(); yield $foo->key() => $foo->current(); yield from $foo; })(); foreach($gen as $k => $v){ echo $k . " => " . $v . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Foo::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8k4me on line 16 Deprecated: Return type of Foo::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8k4me on line 14 Deprecated: Return type of Foo::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8k4me on line 15 Deprecated: Return type of Foo::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8k4me on line 10 Deprecated: Return type of Foo::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/8k4me on line 5 rewind 1 => 1 2 => 2 rewind 3 => 3 4 => 4 5 => 5

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:
66.54 ms | 403 KiB | 8 Q