1--TEST-- 2SPL: FixedArray: overriding getIterator() 3--FILE-- 4<?php 5class A extends SplFixedArray 6{ 7 public function getIterator(): Iterator 8 { 9 $iterator = parent::getIterator(); 10 while ($iterator->valid()) { 11 echo "In A: key={$iterator->key()} value={$iterator->current()}\n"; 12 yield $iterator->key() => $iterator->current(); 13 $iterator->next(); 14 } 15 } 16} 17 18echo "==SplFixedArray instance==\n"; 19$a = new SplFixedArray(3); 20$a[0] = "a"; 21$a[1] = "b"; 22$a[2] = "c"; 23foreach ($a as $k => $v) { 24 echo "$k => $v\n"; 25} 26 27echo "==Subclass instance==\n"; 28$a = new A(3); 29$a[0] = "d"; 30$a[1] = "e"; 31$a[2] = "f"; 32foreach ($a as $k => $v) { 33 echo "$k => $v\n"; 34} 35?> 36--EXPECT-- 37==SplFixedArray instance== 380 => a 391 => b 402 => c 41==Subclass instance== 42In A: key=0 value=d 430 => d 44In A: key=1 value=e 451 => e 46In A: key=2 value=f 472 => f 48