3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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)," "; } // Weird result from neglecting to unset $value ... foreach($dataContainer as $value){ echo $value)," "; }
Output for 5.4.0 - 5.4.22
Parse error: syntax error, unexpected '$value' (T_VARIABLE) in /in/18s6I on line 11
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_VARIABLE in /in/18s6I on line 11
Process exited with code 255.