xref: /PHP-5.4/ext/spl/tests/iterator_052.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);
37$it->show();
38
39$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES);
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(1) {
66    [0]=>
67    string(3) "1,2"
68  }
69  [1]=>
70  array(1) {
71    [0]=>
72    string(1) "1"
73  }
74  [2]=>
75  array(1) {
76    [0]=>
77    string(1) "2"
78  }
79}
80bool(true)
81int(2)
82array(3) {
83  [0]=>
84  array(1) {
85    [0]=>
86    string(3) "1,2"
87  }
88  [1]=>
89  array(1) {
90    [0]=>
91    string(1) "1"
92  }
93  [2]=>
94  array(1) {
95    [0]=>
96    string(1) "2"
97  }
98}
99bool(true)
100int(3)
101array(3) {
102  [0]=>
103  array(0) {
104  }
105  [1]=>
106  array(0) {
107  }
108  [2]=>
109  array(0) {
110  }
111}
112bool(true)
113int(4)
114array(3) {
115  [0]=>
116  array(0) {
117  }
118  [1]=>
119  array(0) {
120  }
121  [2]=>
122  array(0) {
123  }
124}
125
126Notice: Array to string conversion in %siterator_052.php on line %d
127bool(true)
128int(5)
129array(3) {
130  [0]=>
131  array(0) {
132  }
133  [1]=>
134  array(0) {
135  }
136  [2]=>
137  array(0) {
138  }
139}
140bool(true)
141int(6)
142array(3) {
143  [0]=>
144  array(0) {
145  }
146  [1]=>
147  array(0) {
148  }
149  [2]=>
150  array(0) {
151  }
152}
153bool(true)
154int(7)
155array(3) {
156  [0]=>
157  array(0) {
158  }
159  [1]=>
160  array(0) {
161  }
162  [2]=>
163  array(0) {
164  }
165}
166bool(true)
167int(8)
168array(3) {
169  [0]=>
170  array(0) {
171  }
172  [1]=>
173  array(0) {
174  }
175  [2]=>
176  array(0) {
177  }
178}
179bool(true)
180int(0)
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(1)
195array(2) {
196  [0]=>
197  array(2) {
198    [0]=>
199    string(1) "1"
200    [1]=>
201    string(1) "2"
202  }
203  [1]=>
204  array(2) {
205    [0]=>
206    string(1) "1"
207    [1]=>
208    string(1) "2"
209  }
210}
211bool(true)
212int(2)
213array(2) {
214  [0]=>
215  array(3) {
216    [0]=>
217    string(1) "1"
218    [1]=>
219    string(1) "2"
220    [2]=>
221    string(1) "3"
222  }
223  [1]=>
224  array(3) {
225    [0]=>
226    string(1) "1"
227    [1]=>
228    string(1) "2"
229    [2]=>
230    string(1) "3"
231  }
232}
233bool(true)
234int(3)
235array(2) {
236  [0]=>
237  array(0) {
238  }
239  [1]=>
240  array(0) {
241  }
242}
243bool(true)
244int(4)
245array(2) {
246  [0]=>
247  array(0) {
248  }
249  [1]=>
250  array(0) {
251  }
252}
253
254Notice: Array to string conversion in %siterator_052.php on line %d
255bool(true)
256int(5)
257array(2) {
258  [0]=>
259  array(0) {
260  }
261  [1]=>
262  array(0) {
263  }
264}
265bool(true)
266int(6)
267array(2) {
268  [0]=>
269  array(0) {
270  }
271  [1]=>
272  array(0) {
273  }
274}
275bool(true)
276int(7)
277array(2) {
278  [0]=>
279  array(0) {
280  }
281  [1]=>
282  array(0) {
283  }
284}
285bool(true)
286int(8)
287array(2) {
288  [0]=>
289  array(0) {
290  }
291  [1]=>
292  array(0) {
293  }
294}
295object(ArrayIterator)#%d (1) {
296  ["storage":"ArrayIterator":private]=>
297  array(9) {
298    [0]=>
299    %s(1) "1"
300    [1]=>
301    %s(3) "1,2"
302    [2]=>
303    %s(5) "1,2,3"
304    [3]=>
305    %s(0) ""
306    [4]=>
307    NULL
308    [5]=>
309    array(0) {
310    }
311    [6]=>
312    %s(6) "FooBar"
313    [7]=>
314    %s(1) ","
315    [8]=>
316    %s(2) ",,"
317  }
318}
319===DONE===
320