3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements \Iterator { private $items = []; public function __construct(iterable $items){ $this->items = $items; } public function rewind() : void { reset($this->items); } public function key() { return key($this->items); } public function next() { $n = next($this->items); return is_object($n) ? clone($n) : $n; } public function valid() : bool { $key = key($this->items); return $key !== null && $key !== false; } public function current() { $current = current($this->items); return clone($current); } } $items = []; for($i=0; $i<6; $i++){ $items[$i] = new stdClass(); $items[$i]->number = random_int(1,1000); } $test = new Test($items); foreach($test as $t){ echo \spl_object_hash($t)."\n"; }

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
158.64 ms | 1363 KiB | 16 Q