3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class values implements Iterator { private $_data = null; // array or object private $_keys = array(); private $_key = false; public function __construct($data = null){ $this->_data = $data; } public function current(){ return $this->_data->{"{$this->_key}"}; } public function key(){ return $this->_key; } public function next(){ $this->_key = next($this->_keys); } public function rewind(){ $this->_keys = array(); foreach ($this->_data as $k => $v){ $this->_keys[] = $k; } $this->_key = reset($this->_keys); } public function valid(){ if (false === $this->_key){ return false; } return isset($this->_data->{"{$this->_key}"}); } } $values = new values(new DateTime()); foreach($values as $k => $v) { var_dump($k, $v); }
Output for 7.1.0
string(4) "date" string(26) "2014-05-13 11:19:47.004186" string(13) "timezone_type" int(3) string(8) "timezone" string(16) "Europe/Amsterdam"
Output for 5.4.30 - 5.4.45, 5.5.14 - 7.0.14
string(4) "date" string(26) "2014-05-13 11:19:47.000000" string(13) "timezone_type" int(3) string(8) "timezone" string(16) "Europe/Amsterdam"
Output for 5.3.0 - 5.4.29, 5.5.0 - 5.5.13
string(4) "date" string(19) "2014-05-13 11:19:47" string(13) "timezone_type" int(3) string(8) "timezone" string(16) "Europe/Amsterdam"
Output for 5.2.0 - 5.2.17
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/kaZ3W on line 35
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/kaZ3W on line 3
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 '{' in /in/kaZ3W on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/kaZ3W on line 3
Process exited with code 255.