xref: /PHP-5.4/ext/spl/tests/iterator_053.phpt (revision 610c7fbe)
1--TEST--
2SPL: RegexIterator::ALL_MATCHES
3--FILE--
4<?php
5
6class MyRegexIterator extends RegexIterator
7{
8	public $uk, $re;
9
10	function __construct($it, $re, $mode, $flags = 0)
11	{
12		$this->uk = $flags & self::USE_KEY;
13		$this->re = $re;
14		parent::__construct($it, $re, $mode, $flags);
15	}
16
17	function show()
18	{
19		foreach($this as $k => $v)
20		{
21			var_dump($k);
22			var_dump($v);
23		}
24	}
25
26	function accept()
27	{
28		@preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub);
29		$ret = parent::accept();
30		var_dump($sub == $this->current());
31		return $ret;
32	}
33}
34
35$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
36$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
37$it->show();
38
39$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
40$it->show();
41
42var_dump($ar);
43
44?>
45===DONE===
46<?php exit(0); ?>
47--EXPECTF--
48bool(true)
49int(0)
50array(3) {
51  [0]=>
52  array(0) {
53  }
54  [1]=>
55  array(0) {
56  }
57  [2]=>
58  array(0) {
59  }
60}
61bool(true)
62int(1)
63array(3) {
64  [0]=>
65  array(0) {
66  }
67  [1]=>
68  array(0) {
69  }
70  [2]=>
71  array(0) {
72  }
73}
74bool(true)
75int(2)
76array(3) {
77  [0]=>
78  array(0) {
79  }
80  [1]=>
81  array(0) {
82  }
83  [2]=>
84  array(0) {
85  }
86}
87bool(true)
88int(3)
89array(3) {
90  [0]=>
91  array(0) {
92  }
93  [1]=>
94  array(0) {
95  }
96  [2]=>
97  array(0) {
98  }
99}
100bool(true)
101int(4)
102array(3) {
103  [0]=>
104  array(0) {
105  }
106  [1]=>
107  array(0) {
108  }
109  [2]=>
110  array(0) {
111  }
112}
113bool(true)
114int(5)
115array(3) {
116  [0]=>
117  array(0) {
118  }
119  [1]=>
120  array(0) {
121  }
122  [2]=>
123  array(0) {
124  }
125}
126bool(true)
127int(6)
128array(3) {
129  [0]=>
130  array(0) {
131  }
132  [1]=>
133  array(0) {
134  }
135  [2]=>
136  array(0) {
137  }
138}
139bool(true)
140int(7)
141array(3) {
142  [0]=>
143  array(0) {
144  }
145  [1]=>
146  array(0) {
147  }
148  [2]=>
149  array(0) {
150  }
151}
152bool(true)
153int(8)
154array(3) {
155  [0]=>
156  array(0) {
157  }
158  [1]=>
159  array(0) {
160  }
161  [2]=>
162  array(0) {
163  }
164}
165bool(true)
166int(0)
167array(2) {
168  [0]=>
169  array(1) {
170    [0]=>
171    string(1) "0"
172  }
173  [1]=>
174  array(1) {
175    [0]=>
176    string(1) "0"
177  }
178}
179bool(true)
180int(1)
181array(2) {
182  [0]=>
183  array(1) {
184    [0]=>
185    string(1) "1"
186  }
187  [1]=>
188  array(1) {
189    [0]=>
190    string(1) "1"
191  }
192}
193bool(true)
194int(2)
195array(2) {
196  [0]=>
197  array(1) {
198    [0]=>
199    string(1) "2"
200  }
201  [1]=>
202  array(1) {
203    [0]=>
204    string(1) "2"
205  }
206}
207bool(true)
208int(3)
209array(2) {
210  [0]=>
211  array(1) {
212    [0]=>
213    string(1) "3"
214  }
215  [1]=>
216  array(1) {
217    [0]=>
218    string(1) "3"
219  }
220}
221bool(true)
222int(4)
223array(2) {
224  [0]=>
225  array(1) {
226    [0]=>
227    string(1) "4"
228  }
229  [1]=>
230  array(1) {
231    [0]=>
232    string(1) "4"
233  }
234}
235bool(true)
236int(5)
237array(2) {
238  [0]=>
239  array(1) {
240    [0]=>
241    string(1) "5"
242  }
243  [1]=>
244  array(1) {
245    [0]=>
246    string(1) "5"
247  }
248}
249bool(true)
250int(6)
251array(2) {
252  [0]=>
253  array(1) {
254    [0]=>
255    string(1) "6"
256  }
257  [1]=>
258  array(1) {
259    [0]=>
260    string(1) "6"
261  }
262}
263bool(true)
264int(7)
265array(2) {
266  [0]=>
267  array(1) {
268    [0]=>
269    string(1) "7"
270  }
271  [1]=>
272  array(1) {
273    [0]=>
274    string(1) "7"
275  }
276}
277bool(true)
278int(8)
279array(2) {
280  [0]=>
281  array(1) {
282    [0]=>
283    string(1) "8"
284  }
285  [1]=>
286  array(1) {
287    [0]=>
288    string(1) "8"
289  }
290}
291object(ArrayIterator)#%d (1) {
292  ["storage":"ArrayIterator":private]=>
293  array(9) {
294    [0]=>
295    %s(1) "1"
296    [1]=>
297    %s(3) "1,2"
298    [2]=>
299    %s(5) "1,2,3"
300    [3]=>
301    %s(0) ""
302    [4]=>
303    NULL
304    [5]=>
305    array(0) {
306    }
307    [6]=>
308    %s(6) "FooBar"
309    [7]=>
310    %s(1) ","
311    [8]=>
312    %s(2) ",,"
313  }
314}
315===DONE===
316