3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 ArrayIterator(\$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/WK17Q 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/WK17Q on line 27
Process exited with code 255.