3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Gen implements Iterator { private $myArray; public function __construct( $n ) { $this->myArray = range(0,$n-1); } function rewind() { return reset($this->myArray); } function current() { return current($this->myArray); } function key() { return key($this->myArray); } function next() { return next($this->myArray); } function valid() { return key($this->myArray) !== null; } function __destruct(){ echo ' - Gen is data drained!'; } } $gen = new Gen(3); // iterable object can be used in foreach foreach ($gen as $g) { echo $gen->current(); // sequentially making data available }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Gen::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/G4nFp on line 12 Deprecated: Return type of Gen::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/G4nFp on line 18 Deprecated: Return type of Gen::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/G4nFp on line 15 Deprecated: Return type of Gen::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/G4nFp on line 21 Deprecated: Return type of Gen::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/G4nFp on line 9 012 - Gen is data drained!

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.86 ms | 403 KiB | 8 Q