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