3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyValue { private $value; function get() { return $this->value; } function set($value) { $this->value = $value; } function delete() { $this->value = null; } } class MyIterator implements Iterator { private $data; private $key = 0; function __construct() { $this->data = new MyValue(); } function __destruct() { $this->data->delete(); } function current() { $this->data->set($this->key); return $this->data; } function key() { return $this->key; } function next() { ++$this->key; } function rewind() { $this->key = 0; } function valid() { return $this->key < 10; } } function iterate() { $out = array(); $values = new MyIterator(); foreach ($values as $value) { $out[] = $value; } print_r($out); return $out; } $values = iterate(); print_r($values);
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => MyValue Object ( [value:MyValue:private] => 9 ) [1] => MyValue Object ( [value:MyValue:private] => 9 ) [2] => MyValue Object ( [value:MyValue:private] => 9 ) [3] => MyValue Object ( [value:MyValue:private] => 9 ) [4] => MyValue Object ( [value:MyValue:private] => 9 ) [5] => MyValue Object ( [value:MyValue:private] => 9 ) [6] => MyValue Object ( [value:MyValue:private] => 9 ) [7] => MyValue Object ( [value:MyValue:private] => 9 ) [8] => MyValue Object ( [value:MyValue:private] => 9 ) [9] => MyValue Object ( [value:MyValue:private] => 9 ) ) Array ( [0] => MyValue Object ( [value:MyValue:private] => ) [1] => MyValue Object ( [value:MyValue:private] => ) [2] => MyValue Object ( [value:MyValue:private] => ) [3] => MyValue Object ( [value:MyValue:private] => ) [4] => MyValue Object ( [value:MyValue:private] => ) [5] => MyValue Object ( [value:MyValue:private] => ) [6] => MyValue Object ( [value:MyValue:private] => ) [7] => MyValue Object ( [value:MyValue:private] => ) [8] => MyValue Object ( [value:MyValue:private] => ) [9] => MyValue Object ( [value:MyValue:private] => ) )
Output for 5.0.0 - 5.2.17
Array ( [0] => MyValue Object ( [value:private] => 9 ) [1] => MyValue Object ( [value:private] => 9 ) [2] => MyValue Object ( [value:private] => 9 ) [3] => MyValue Object ( [value:private] => 9 ) [4] => MyValue Object ( [value:private] => 9 ) [5] => MyValue Object ( [value:private] => 9 ) [6] => MyValue Object ( [value:private] => 9 ) [7] => MyValue Object ( [value:private] => 9 ) [8] => MyValue Object ( [value:private] => 9 ) [9] => MyValue Object ( [value:private] => 9 ) ) Array ( [0] => MyValue Object ( [value:private] => ) [1] => MyValue Object ( [value:private] => ) [2] => MyValue Object ( [value:private] => ) [3] => MyValue Object ( [value:private] => ) [4] => MyValue Object ( [value:private] => ) [5] => MyValue Object ( [value:private] => ) [6] => MyValue Object ( [value:private] => ) [7] => MyValue Object ( [value:private] => ) [8] => MyValue Object ( [value:private] => ) [9] => MyValue Object ( [value:private] => ) )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/aXaT1 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/aXaT1 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/aXaT1 on line 4
Process exited with code 255.