Annotation of embedaddon/php/ext/spl/tests/iterator_039.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: LimitIterator and backward seeking
! 3: --FILE--
! 4: <?php
! 5:
! 6: class 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:
! 50: foreach($it as $k => $v)
! 51: {
! 52: var_dump($k);
! 53: var_dump($v);
! 54: }
! 55:
! 56: echo "===SEEK===\n";
! 57:
! 58: $it->seek(2);
! 59:
! 60: echo "===LOOP===\n";
! 61:
! 62: foreach(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--
! 72: NumericArrayIterator::__construct
! 73: NumericArrayIterator::rewind
! 74: NumericArrayIterator::valid
! 75: NumericArrayIterator::valid
! 76: NumericArrayIterator::current
! 77: NumericArrayIterator::key
! 78: int(0)
! 79: int(12)
! 80: NumericArrayIterator::next
! 81: NumericArrayIterator::valid
! 82: NumericArrayIterator::current
! 83: NumericArrayIterator::key
! 84: int(1)
! 85: int(25)
! 86: NumericArrayIterator::next
! 87: NumericArrayIterator::valid
! 88: NumericArrayIterator::current
! 89: NumericArrayIterator::key
! 90: int(2)
! 91: int(42)
! 92: NumericArrayIterator::next
! 93: NumericArrayIterator::valid
! 94: NumericArrayIterator::current
! 95: NumericArrayIterator::key
! 96: int(3)
! 97: int(56)
! 98: NumericArrayIterator::next
! 99: NumericArrayIterator::valid
! 100: ===SEEK===
! 101: NumericArrayIterator::rewind
! 102: NumericArrayIterator::valid
! 103: NumericArrayIterator::next
! 104: NumericArrayIterator::valid
! 105: NumericArrayIterator::next
! 106: NumericArrayIterator::valid
! 107: NumericArrayIterator::valid
! 108: NumericArrayIterator::current
! 109: NumericArrayIterator::key
! 110: ===LOOP===
! 111: int(2)
! 112: int(42)
! 113: NumericArrayIterator::next
! 114: NumericArrayIterator::valid
! 115: NumericArrayIterator::current
! 116: NumericArrayIterator::key
! 117: int(3)
! 118: int(56)
! 119: NumericArrayIterator::next
! 120: NumericArrayIterator::valid
! 121: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>