3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataContainer implements IteratorAggregate { protected $data; public function __construct(array $data) { $this->data = $data; } public function &getIterator() { foreach ($this->data as &$value) { echo 'in foreach ...'; yield $value; } } } $dataContainer = new DataContainer([77, 78, 79]); var_dump($dataContainer); foreach ($dataContainer as &$value) { echo ($value instanceof Generator)? 'true': 'false'; $value *= -1; } var_dump($dataContainer,$value); // -77,-78,&int-79 // Must unset $value ... foreach($dataContainer as $value){ var_dump($value); } var_dump($dataContainer);// -77,-78,&int-78
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/LQQNE on line 7 object(DataContainer)#1 (1) { ["data":protected]=> array(3) { [0]=> int(77) [1]=> int(78) [2]=> int(79) } } in foreach ...falsein foreach ...falsein foreach ...falseobject(DataContainer)#1 (1) { ["data":protected]=> array(3) { [0]=> int(-77) [1]=> int(-78) [2]=> &int(-79) } } int(-79) in foreach ...int(-77) in foreach ...int(-78) in foreach ...int(-78) 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:
38.28 ms | 403 KiB | 8 Q