xref: /PHP-7.3/ext/spl/tests/iterator_052.phpt (revision 782352c5)
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)
49bool(true)
50int(1)
51array(3) {
52  [0]=>
53  array(1) {
54    [0]=>
55    string(3) "1,2"
56  }
57  [1]=>
58  array(1) {
59    [0]=>
60    string(1) "1"
61  }
62  [2]=>
63  array(1) {
64    [0]=>
65    string(1) "2"
66  }
67}
68bool(true)
69int(2)
70array(3) {
71  [0]=>
72  array(1) {
73    [0]=>
74    string(3) "1,2"
75  }
76  [1]=>
77  array(1) {
78    [0]=>
79    string(1) "1"
80  }
81  [2]=>
82  array(1) {
83    [0]=>
84    string(1) "2"
85  }
86}
87bool(true)
88bool(true)
89bool(false)
90bool(true)
91bool(true)
92bool(true)
93bool(true)
94int(0)
95array(2) {
96  [0]=>
97  array(1) {
98    [0]=>
99    string(1) "1"
100  }
101  [1]=>
102  array(1) {
103    [0]=>
104    string(1) "1"
105  }
106}
107bool(true)
108int(1)
109array(2) {
110  [0]=>
111  array(2) {
112    [0]=>
113    string(1) "1"
114    [1]=>
115    string(1) "2"
116  }
117  [1]=>
118  array(2) {
119    [0]=>
120    string(1) "1"
121    [1]=>
122    string(1) "2"
123  }
124}
125bool(true)
126int(2)
127array(2) {
128  [0]=>
129  array(3) {
130    [0]=>
131    string(1) "1"
132    [1]=>
133    string(1) "2"
134    [2]=>
135    string(1) "3"
136  }
137  [1]=>
138  array(3) {
139    [0]=>
140    string(1) "1"
141    [1]=>
142    string(1) "2"
143    [2]=>
144    string(1) "3"
145  }
146}
147bool(true)
148bool(true)
149bool(false)
150bool(true)
151bool(true)
152bool(true)
153object(ArrayIterator)#%d (1) {
154  ["storage":"ArrayIterator":private]=>
155  array(9) {
156    [0]=>
157    %s(1) "1"
158    [1]=>
159    %s(3) "1,2"
160    [2]=>
161    %s(5) "1,2,3"
162    [3]=>
163    %s(0) ""
164    [4]=>
165    NULL
166    [5]=>
167    array(0) {
168    }
169    [6]=>
170    %s(6) "FooBar"
171    [7]=>
172    %s(1) ","
173    [8]=>
174    %s(2) ",,"
175  }
176}
177===DONE===
178