xref: /PHP-5.4/ext/spl/tests/iterator_007.phpt (revision 610c7fbe)
1--TEST--
2SPL: NoRewindIterator
3--FILE--
4<?php
5
6class ArrayIteratorEx extends ArrayIterator
7{
8	function rewind()
9	{
10		echo __METHOD__ . "\n";
11		parent::rewind();
12	}
13	function valid()
14	{
15		echo __METHOD__ . "\n";
16		return parent::valid();
17	}
18	function current()
19	{
20		echo __METHOD__ . "\n";
21		return parent::current();
22	}
23	function key()
24	{
25		echo __METHOD__ . "\n";
26		return parent::key();
27	}
28	function next()
29	{
30		echo __METHOD__ . "\n";
31		parent::next();
32	}
33}
34
35class NoRewindIteratorEx extends NoRewindIterator
36{
37	function rewind()
38	{
39		echo __METHOD__ . "\n";
40		parent::rewind();
41	}
42	function valid()
43	{
44		echo __METHOD__ . "\n";
45		return parent::valid();
46	}
47	function current()
48	{
49		echo __METHOD__ . "\n";
50		return parent::current();
51	}
52	function key()
53	{
54		echo __METHOD__ . "\n";
55		return parent::key();
56	}
57	function next()
58	{
59		echo __METHOD__ . "\n";
60		parent::next();
61	}
62}
63
64$it = new NoRewindIteratorEx(new ArrayIteratorEx(range(0,3)));
65
66echo "===0===\n";
67foreach ($it->getInnerIterator() as $v) {
68	var_dump($v);
69}
70
71echo "===1===\n";
72foreach ($it as $v) {
73	var_dump($v);
74}
75
76$pos =0;
77
78$it = new NoRewindIteratorEx(new ArrayIteratorEx(range(0,3)));
79
80echo "===2===\n";
81foreach ($it as $v) {
82	var_dump($v);
83	if ($pos++ > 1) {
84		break;
85	}
86}
87
88echo "===3===\n";
89foreach ($it as $v) {
90	var_dump($v);
91}
92
93echo "===4===\n";
94foreach ($it as $v) {
95	var_dump($v);
96}
97?>
98===DONE===
99<?php exit(0); ?>
100--EXPECT--
101===0===
102ArrayIteratorEx::rewind
103ArrayIteratorEx::valid
104ArrayIteratorEx::current
105int(0)
106ArrayIteratorEx::next
107ArrayIteratorEx::valid
108ArrayIteratorEx::current
109int(1)
110ArrayIteratorEx::next
111ArrayIteratorEx::valid
112ArrayIteratorEx::current
113int(2)
114ArrayIteratorEx::next
115ArrayIteratorEx::valid
116ArrayIteratorEx::current
117int(3)
118ArrayIteratorEx::next
119ArrayIteratorEx::valid
120===1===
121NoRewindIteratorEx::rewind
122NoRewindIteratorEx::valid
123ArrayIteratorEx::valid
124===2===
125NoRewindIteratorEx::rewind
126NoRewindIteratorEx::valid
127ArrayIteratorEx::valid
128NoRewindIteratorEx::current
129ArrayIteratorEx::current
130int(0)
131NoRewindIteratorEx::next
132ArrayIteratorEx::next
133NoRewindIteratorEx::valid
134ArrayIteratorEx::valid
135NoRewindIteratorEx::current
136ArrayIteratorEx::current
137int(1)
138NoRewindIteratorEx::next
139ArrayIteratorEx::next
140NoRewindIteratorEx::valid
141ArrayIteratorEx::valid
142NoRewindIteratorEx::current
143ArrayIteratorEx::current
144int(2)
145===3===
146NoRewindIteratorEx::rewind
147NoRewindIteratorEx::valid
148ArrayIteratorEx::valid
149NoRewindIteratorEx::current
150int(2)
151NoRewindIteratorEx::next
152ArrayIteratorEx::next
153NoRewindIteratorEx::valid
154ArrayIteratorEx::valid
155NoRewindIteratorEx::current
156ArrayIteratorEx::current
157int(3)
158NoRewindIteratorEx::next
159ArrayIteratorEx::next
160NoRewindIteratorEx::valid
161ArrayIteratorEx::valid
162===4===
163NoRewindIteratorEx::rewind
164NoRewindIteratorEx::valid
165ArrayIteratorEx::valid
166===DONE===
167