1--TEST-- 2SPL: LimitIterator and backward seeking 3--FILE-- 4<?php 5 6class NumericArrayIterator implements Iterator 7{ 8 protected $a; 9 protected $i = 0; 10 11 public function __construct($a) 12 { 13 echo __METHOD__ . "\n"; 14 $this->a = $a; 15 } 16 17 public function valid() 18 { 19 echo __METHOD__ . "\n"; 20 return $this->i < count($this->a); 21 } 22 23 public function rewind() 24 { 25 echo __METHOD__ . "\n"; 26 $this->i = 0; 27 } 28 29 public function key() 30 { 31 echo __METHOD__ . "\n"; 32 return $this->i; 33 } 34 35 public function current() 36 { 37 echo __METHOD__ . "\n"; 38 return $this->a[$this->i]; 39 } 40 41 public function next() 42 { 43 echo __METHOD__ . "\n"; 44 $this->i++; 45 } 46} 47 48$it = new LimitIterator(new NumericArrayIterator(array(12, 25, 42, 56))); 49 50foreach($it as $k => $v) 51{ 52 var_dump($k); 53 var_dump($v); 54} 55 56echo "===SEEK===\n"; 57 58$it->seek(2); 59 60echo "===LOOP===\n"; 61 62foreach(new NoRewindIterator($it) as $k => $v) 63{ 64 var_dump($k); 65 var_dump($v); 66} 67 68?> 69===DONE=== 70<?php exit(0); ?> 71--EXPECT-- 72NumericArrayIterator::__construct 73NumericArrayIterator::rewind 74NumericArrayIterator::valid 75NumericArrayIterator::valid 76NumericArrayIterator::current 77NumericArrayIterator::key 78int(0) 79int(12) 80NumericArrayIterator::next 81NumericArrayIterator::valid 82NumericArrayIterator::current 83NumericArrayIterator::key 84int(1) 85int(25) 86NumericArrayIterator::next 87NumericArrayIterator::valid 88NumericArrayIterator::current 89NumericArrayIterator::key 90int(2) 91int(42) 92NumericArrayIterator::next 93NumericArrayIterator::valid 94NumericArrayIterator::current 95NumericArrayIterator::key 96int(3) 97int(56) 98NumericArrayIterator::next 99NumericArrayIterator::valid 100===SEEK=== 101NumericArrayIterator::rewind 102NumericArrayIterator::valid 103NumericArrayIterator::next 104NumericArrayIterator::valid 105NumericArrayIterator::next 106NumericArrayIterator::valid 107NumericArrayIterator::valid 108NumericArrayIterator::current 109NumericArrayIterator::key 110===LOOP=== 111int(2) 112int(42) 113NumericArrayIterator::next 114NumericArrayIterator::valid 115NumericArrayIterator::current 116NumericArrayIterator::key 117int(3) 118int(56) 119NumericArrayIterator::next 120NumericArrayIterator::valid 121===DONE=== 122