3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class values implements IteratorAggregate { protected $iterator = null; protected $data = null; public function __construct($data) { $this->data = $data; } public function getIterator() { if (null === $this->iterator){ if(is_array($this->data)) { $this->iterator = new ArrayObject($this->data); } else if(is_object($objOrArr)) { $this->iterator = new ArrayObject(get_object_vars($this->data)); } else { throw new Exception('$objOrArray is neither an array or an object'); } } return $this->iterator; } } $values = new values(new DateTime()); for ($i = 0; $i < 100; $i++){ foreach($values as $k => $v) { var_dump($k, $v); } }
Output for 7.0.0 - 7.1.0
Notice: Undefined variable: objOrArr in /in/GUlTH on line 17 Fatal error: Uncaught Exception: $objOrArray is neither an array or an object in /in/GUlTH:20 Stack trace: #0 /in/GUlTH(30): values->getIterator() #1 {main} thrown in /in/GUlTH on line 20
Process exited with code 255.
Output for 5.2.0 - 5.6.28
Notice: Undefined variable: objOrArr in /in/GUlTH on line 17 Fatal error: Uncaught exception 'Exception' with message '$objOrArray is neither an array or an object' in /in/GUlTH:20 Stack trace: #0 /in/GUlTH(30): values->getIterator() #1 {main} thrown in /in/GUlTH on line 20
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/GUlTH on line 27
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/GUlTH 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/GUlTH on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/GUlTH on line 3
Process exited with code 255.