3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataContainer implements IteratorAggregate { // create an external Iterator: protected $data; public function __construct(array $data) { $this->data = $data; } public function &getIterator() { foreach ($this->data as &$value) { yield $value; } } } $dataContainer = new DataContainer([77, 78, 79]); foreach ($dataContainer as &$value) { echo $value *= -1,"\n"; } // Weird result from neglecting to unset $value ... foreach($dataContainer as $value); var_dump($dataContainer);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of & DataContainer::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/rK9Ff on line 9 -77 -78 -79 object(DataContainer)#1 (1) { ["data":protected]=> array(3) { [0]=> int(-77) [1]=> int(-78) [2]=> &int(-78) } }

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:
37.76 ms | 402 KiB | 8 Q