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 $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 8.2.14 - 8.2.17, 8.3.1 - 8.3.4
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/l558T on line 11 Fatal error: Uncaught Error: Cannot use object of type DataContainer as array in /in/l558T:20 Stack trace: #0 {main} Next 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 8.1.0 - 8.1.27, 8.2.0 - 8.2.13, 8.3.0
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/l558T on line 11 Fatal error: Uncaught Error: Cannot use object of type DataContainer as array in /in/l558T:20 Stack trace: #0 {main} Next Error: Cannot use object as array in /in/l558T:20 Stack trace: #0 {main} thrown in /in/l558T on line 20
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Fatal error: Uncaught Error: Cannot use object of type DataContainer as array in /in/l558T:20 Stack trace: #0 {main} Next Error: Cannot use object as array in /in/l558T:20 Stack trace: #0 {main} thrown in /in/l558T on line 20
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
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.5.35, 5.6.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.2.17, 5.3.0 - 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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
258.71 ms | 401 KiB | 386 Q