3v4l.org

run code in 300+ PHP versions simultaneously
<?php class lazyNew implements Iterator { private $obj = null; private $func ; public function __construct($func) { $this->func = $func; } public function init() { if ($this->obj === null) { $func = $this->func; $this->obj = $func(); } return $this->obj; } public function current() { return $this->init()->current(); } public function valid() { echo "valid on ".get_class($this)."\n"; //also try var_dump($this) return $this->init()->valid(); } public function next() { return $this->init()->next(); } public function key() { return $this->init()->key(); } public function rewind() { echo "rewind on ".get_class($this)."\n"; return $this->init()->rewind(); } } $P = new lazyNew(function() use (&$P) { return $P = new ArrayIterator(array(1,2,3,4,5)); }); foreach ($P as $val) echo($val); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of lazyNew::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 15 Deprecated: Return type of lazyNew::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 23 Deprecated: Return type of lazyNew::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 26 Deprecated: Return type of lazyNew::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 18 Deprecated: Return type of lazyNew::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZcpQZ on line 29 rewind on lazyNew valid on lazyNew 1valid on lazyNew 2valid on lazyNew 3valid on lazyNew 4valid on lazyNew 5valid on lazyNew

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