--TEST-- ZE2 iterators must be implemented --FILE-- num; } function next(): void { echo __METHOD__ . "\n"; $this->num++; } function valid(): bool { echo __METHOD__ . "\n"; return $this->num < $this->max; } function key(): mixed { echo __METHOD__ . "\n"; switch($this->num) { case 0: return "1st"; case 1: return "2nd"; case 2: return "3rd"; default: return "???"; } } } $obj = new c2(); foreach($obj as $v => $w) { echo "object:$v=>$w\n"; } print "Done\n"; ?> --EXPECT-- 1st try 2nd try object:max=>3 object:num=>0 Done