$o = new class ([1, 2, 3]) implements \Iterator {
protected array $data;
protected int $position;
public function __construct(array $data) { $this->data = $data; $this->position = 0; }
public function current () { return $this->data[$this->position]; }
public function key () { return $this->position; }
public function next () { ++$this->position; }
public function rewind () { $this->position = 0; }
public function valid () { return isset($this->data[$this->position]); }
};
foreach ($o as $i => $v) echo "$i => $v", PHP_EOL;