xref: /PHP-7.4/ext/pcre/tests/bug61780_2.phpt (revision 6311581a)
1--TEST--
2Bug #61780 (Inconsistent PCRE captures in match results): named subpatterns
3--FILE--
4<?php
5preg_match('/(?<a>4)?(?<b>2)?\d/', '23456', $matches, PREG_UNMATCHED_AS_NULL);
6var_export($matches);
7echo "\n\n";
8preg_match('/(?<a>4)?(?<b>2)?\d/', '23456', $matches, PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL);
9var_export($matches);
10echo "\n\n";
11preg_match_all('/(?<a>4)?(?<b>2)?\d/', '123456', $matches, PREG_UNMATCHED_AS_NULL);
12var_export($matches);
13echo "\n\n";
14preg_match_all('/(?<a>4)?(?<b>2)?\d/', '123456', $matches, PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL);
15var_export($matches);
16echo "\n\n";
17preg_match_all('/(?<a>4)?(?<b>2)?\d/', '123456', $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
18var_export($matches);
19echo "\n\n";
20preg_match_all('/(?<a>4)?(?<b>2)?\d/', '123456', $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE | PREG_UNMATCHED_AS_NULL);
21var_export($matches);
22?>
23--EXPECT--
24array (
25  0 => '23',
26  'a' => NULL,
27  1 => NULL,
28  'b' => '2',
29  2 => '2',
30)
31
32array (
33  0 =>
34  array (
35    0 => '23',
36    1 => 0,
37  ),
38  'a' =>
39  array (
40    0 => NULL,
41    1 => -1,
42  ),
43  1 =>
44  array (
45    0 => NULL,
46    1 => -1,
47  ),
48  'b' =>
49  array (
50    0 => '2',
51    1 => 0,
52  ),
53  2 =>
54  array (
55    0 => '2',
56    1 => 0,
57  ),
58)
59
60array (
61  0 =>
62  array (
63    0 => '1',
64    1 => '23',
65    2 => '45',
66    3 => '6',
67  ),
68  'a' =>
69  array (
70    0 => NULL,
71    1 => NULL,
72    2 => '4',
73    3 => NULL,
74  ),
75  1 =>
76  array (
77    0 => NULL,
78    1 => NULL,
79    2 => '4',
80    3 => NULL,
81  ),
82  'b' =>
83  array (
84    0 => NULL,
85    1 => '2',
86    2 => NULL,
87    3 => NULL,
88  ),
89  2 =>
90  array (
91    0 => NULL,
92    1 => '2',
93    2 => NULL,
94    3 => NULL,
95  ),
96)
97
98array (
99  0 =>
100  array (
101    0 =>
102    array (
103      0 => '1',
104      1 => 0,
105    ),
106    1 =>
107    array (
108      0 => '23',
109      1 => 1,
110    ),
111    2 =>
112    array (
113      0 => '45',
114      1 => 3,
115    ),
116    3 =>
117    array (
118      0 => '6',
119      1 => 5,
120    ),
121  ),
122  'a' =>
123  array (
124    0 =>
125    array (
126      0 => NULL,
127      1 => -1,
128    ),
129    1 =>
130    array (
131      0 => NULL,
132      1 => -1,
133    ),
134    2 =>
135    array (
136      0 => '4',
137      1 => 3,
138    ),
139    3 =>
140    array (
141      0 => NULL,
142      1 => -1,
143    ),
144  ),
145  1 =>
146  array (
147    0 =>
148    array (
149      0 => NULL,
150      1 => -1,
151    ),
152    1 =>
153    array (
154      0 => NULL,
155      1 => -1,
156    ),
157    2 =>
158    array (
159      0 => '4',
160      1 => 3,
161    ),
162    3 =>
163    array (
164      0 => NULL,
165      1 => -1,
166    ),
167  ),
168  'b' =>
169  array (
170    0 =>
171    array (
172      0 => NULL,
173      1 => -1,
174    ),
175    1 =>
176    array (
177      0 => '2',
178      1 => 1,
179    ),
180    2 =>
181    array (
182      0 => NULL,
183      1 => -1,
184    ),
185    3 =>
186    array (
187      0 => NULL,
188      1 => -1,
189    ),
190  ),
191  2 =>
192  array (
193    0 =>
194    array (
195      0 => NULL,
196      1 => -1,
197    ),
198    1 =>
199    array (
200      0 => '2',
201      1 => 1,
202    ),
203    2 =>
204    array (
205      0 => NULL,
206      1 => -1,
207    ),
208    3 =>
209    array (
210      0 => NULL,
211      1 => -1,
212    ),
213  ),
214)
215
216array (
217  0 =>
218  array (
219    0 => '1',
220    'a' => NULL,
221    1 => NULL,
222    'b' => NULL,
223    2 => NULL,
224  ),
225  1 =>
226  array (
227    0 => '23',
228    'a' => NULL,
229    1 => NULL,
230    'b' => '2',
231    2 => '2',
232  ),
233  2 =>
234  array (
235    0 => '45',
236    'a' => '4',
237    1 => '4',
238    'b' => NULL,
239    2 => NULL,
240  ),
241  3 =>
242  array (
243    0 => '6',
244    'a' => NULL,
245    1 => NULL,
246    'b' => NULL,
247    2 => NULL,
248  ),
249)
250
251array (
252  0 =>
253  array (
254    0 =>
255    array (
256      0 => '1',
257      1 => 0,
258    ),
259    'a' =>
260    array (
261      0 => NULL,
262      1 => -1,
263    ),
264    1 =>
265    array (
266      0 => NULL,
267      1 => -1,
268    ),
269    'b' =>
270    array (
271      0 => NULL,
272      1 => -1,
273    ),
274    2 =>
275    array (
276      0 => NULL,
277      1 => -1,
278    ),
279  ),
280  1 =>
281  array (
282    0 =>
283    array (
284      0 => '23',
285      1 => 1,
286    ),
287    'a' =>
288    array (
289      0 => NULL,
290      1 => -1,
291    ),
292    1 =>
293    array (
294      0 => NULL,
295      1 => -1,
296    ),
297    'b' =>
298    array (
299      0 => '2',
300      1 => 1,
301    ),
302    2 =>
303    array (
304      0 => '2',
305      1 => 1,
306    ),
307  ),
308  2 =>
309  array (
310    0 =>
311    array (
312      0 => '45',
313      1 => 3,
314    ),
315    'a' =>
316    array (
317      0 => '4',
318      1 => 3,
319    ),
320    1 =>
321    array (
322      0 => '4',
323      1 => 3,
324    ),
325    'b' =>
326    array (
327      0 => NULL,
328      1 => -1,
329    ),
330    2 =>
331    array (
332      0 => NULL,
333      1 => -1,
334    ),
335  ),
336  3 =>
337  array (
338    0 =>
339    array (
340      0 => '6',
341      1 => 5,
342    ),
343    'a' =>
344    array (
345      0 => NULL,
346      1 => -1,
347    ),
348    1 =>
349    array (
350      0 => NULL,
351      1 => -1,
352    ),
353    'b' =>
354    array (
355      0 => NULL,
356      1 => -1,
357    ),
358    2 =>
359    array (
360      0 => NULL,
361      1 => -1,
362    ),
363  ),
364)
365