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