3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class DataContainer implements IteratorAggregate { protected $data; public function __construct(array $data) { $this->data = $data; } public function &getIterator() { foreach ($this->data as $key => &$value) { yield $key => $value; } } } $dataContainer = new DataContainer([1, 2, 3]); foreach (array_keys((array)$dataContainer) as $key) { $dataContainer[$key] *= -1; } var_dump($dataContainer);
Output for 7.0.0 - 7.1.0
Warning: Attempt to assign property of non-object in /in/l558T on line 20 Fatal error: Uncaught Error: Cannot use object of type DataContainer as array in /in/l558T:20 Stack trace: #0 {main} thrown in /in/l558T on line 20
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Fatal error: Cannot use object of type DataContainer as array in /in/l558T on line 20
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/l558T on line 13
Process exited with code 255.
Output for 5.2.3 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/l558T on line 13
Process exited with code 255.
Output for 5.1.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected T_VARIABLE in <b>/in/l558T</b> on line <b>13</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in <b>/in/l558T</b> on line <b>7</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting '{' in <b>/in/l558T</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting '{' in <b>/in/l558T</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `'{'' in <b>/in/l558T</b> on line <b>4</b><br />
Process exited with code 255.