3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myData implements IteratorAggregate { public $property1 = "Public property one"; public $property2 = "Public property two"; public $property3 = "Public property three"; public function __construct() { $this->property4 = "last property"; } public function getIterator() { return new ArrayIterator($this); } } $obj = new myData; echo "foreach (new \$obj)"; foreach($obj as $key => $value) { var_dump($key, $value); echo "\n"; } echo "\nforeach (new ArrayIterator(\$obj))\n" foreach(new ArrayIterator($obj) as $key => $value) { var_dump($key, $value); echo "\n"; }
Output for 5.4.0 - 5.4.26
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ',' or ';' in /in/VJ5Pt on line 27
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_FOREACH, expecting ',' or ';' in /in/VJ5Pt on line 27
Process exited with code 255.

preferences:
186.59 ms | 1395 KiB | 63 Q