1--TEST--
2Test glob() function: usage variations
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. Not valid for Windows');
7}
8if (!defined('GLOB_BRACE')) {
9    die('skip this test requires GLOB_BRACE support');
10}
11?>
12--FILE--
13<?php
14echo "*** Testing glob() : usage variations ***\n";
15
16$file_path = __DIR__;
17
18// temp dir created
19mkdir("$file_path/glob_variation");
20mkdir("$file_path/glob_variation/wonder");
21
22// temp files created
23$fp = fopen("$file_path/glob_variation/wonder12345", "w");
24fclose($fp);
25$fp = fopen("$file_path/glob_variation/wonder;123456", "w");
26fclose($fp);
27
28$patterns = array (
29  "$file_path/glob_variation/*der*",
30  "$file_path/glob_variation/?onder*",
31  "$file_path/glob_variation/w*der?*",
32  "$file_path/glob_variation/*der5",
33  "$file_path/glob_variation/??onder*",
34  "$file_path/glob_variation/***der***",
35  "$file_path/glob_variation/++onder*",
36  "$file_path/glob_variation/WONDER5\0",
37  '$file_path/glob_variation/wonder5',
38  "$file_path/glob_variation/?wonder?",
39  "$file_path/glob_variation/wonder?",
40  TRUE  // boolean true
41);
42$counter = 1;
43/* loop through $patterns to match each $pattern with the files created
44   using glob() */
45foreach($patterns as $pattern) {
46  echo "\n-- Iteration $counter --\n";
47  try {
48    var_dump( glob($pattern) );  // default arguments
49    var_dump( glob($pattern, GLOB_MARK) );
50    var_dump( glob($pattern, GLOB_NOSORT) );
51    var_dump( glob($pattern, GLOB_NOCHECK) );
52    var_dump( glob($pattern, GLOB_NOESCAPE) );
53    var_dump( glob($pattern, GLOB_ERR) );
54  } catch (Error $e) {
55    echo $e->getMessage(), "\n";
56  }
57  $counter++;
58}
59
60echo "\n*** Testing glob() with pattern within braces ***\n";
61var_dump( glob("$file_path/glob_variation/*{5}", GLOB_BRACE) );
62
63// delete temp files and dir
64unlink("$file_path/glob_variation/wonder12345");
65unlink("$file_path/glob_variation/wonder;123456");
66rmdir("$file_path/glob_variation/wonder");
67rmdir("$file_path/glob_variation");
68
69echo "\n*** Testing glob() on directories ***\n";
70// temp dir created to check for pattern matching the sub dir created in it
71mkdir("$file_path/glob_variation/wonder1/wonder2", 0777, true);
72
73$counter = 1;
74/* loop through $patterns to match each $pattern with the directories created
75   using glob() */
76foreach($patterns as $pattern) {
77  echo "-- Iteration $counter --\n";
78  try {
79    var_dump( glob($pattern, GLOB_ONLYDIR) );
80  } catch (Error $e) {
81    echo $e->getMessage(), "\n";
82  }
83  $counter++;
84}
85
86echo "Done\n";
87?>
88--CLEAN--
89<?php
90$file_path = __DIR__;
91rmdir("$file_path/glob_variation/wonder1/wonder2");
92rmdir("$file_path/glob_variation/wonder1/");
93rmdir("$file_path/glob_variation/");
94?>
95--EXPECTF--
96*** Testing glob() : usage variations ***
97
98-- Iteration 1 --
99array(3) {
100  [0]=>
101  string(%d) "%s/glob_variation/wonder"
102  [1]=>
103  string(%d) "%s/glob_variation/wonder12345"
104  [2]=>
105  string(%d) "%s/glob_variation/wonder;123456"
106}
107array(3) {
108  [0]=>
109  string(%d) "%s/glob_variation/wonder/"
110  [1]=>
111  string(%d) "%s/glob_variation/wonder12345"
112  [2]=>
113  string(%d) "%s/glob_variation/wonder;123456"
114}
115array(3) {
116  [0]=>
117  string(%d) "%s"
118  [1]=>
119  string(%d) "%s"
120  [2]=>
121  string(%d) "%s"
122}
123array(3) {
124  [0]=>
125  string(%d) "%s/glob_variation/wonder"
126  [1]=>
127  string(%d) "%s/glob_variation/wonder12345"
128  [2]=>
129  string(%d) "%s/glob_variation/wonder;123456"
130}
131array(3) {
132  [0]=>
133  string(%d) "%s/glob_variation/wonder"
134  [1]=>
135  string(%d) "%s/glob_variation/wonder12345"
136  [2]=>
137  string(%d) "%s/glob_variation/wonder;123456"
138}
139array(3) {
140  [0]=>
141  string(%d) "%s/glob_variation/wonder"
142  [1]=>
143  string(%d) "%s/glob_variation/wonder12345"
144  [2]=>
145  string(%d) "%s/glob_variation/wonder;123456"
146}
147
148-- Iteration 2 --
149array(3) {
150  [0]=>
151  string(%d) "%s/glob_variation/wonder"
152  [1]=>
153  string(%d) "%s/glob_variation/wonder12345"
154  [2]=>
155  string(%d) "%s/glob_variation/wonder;123456"
156}
157array(3) {
158  [0]=>
159  string(%d) "%s/glob_variation/wonder/"
160  [1]=>
161  string(%d) "%s/glob_variation/wonder12345"
162  [2]=>
163  string(%d) "%s/glob_variation/wonder;123456"
164}
165array(3) {
166  [0]=>
167  string(%d) "%s"
168  [1]=>
169  string(%d) "%s"
170  [2]=>
171  string(%d) "%s"
172}
173array(3) {
174  [0]=>
175  string(%d) "%s/glob_variation/wonder"
176  [1]=>
177  string(%d) "%s/glob_variation/wonder12345"
178  [2]=>
179  string(%d) "%s/glob_variation/wonder;123456"
180}
181array(3) {
182  [0]=>
183  string(%d) "%s/glob_variation/wonder"
184  [1]=>
185  string(%d) "%s/glob_variation/wonder12345"
186  [2]=>
187  string(%d) "%s/glob_variation/wonder;123456"
188}
189array(3) {
190  [0]=>
191  string(%d) "%s/glob_variation/wonder"
192  [1]=>
193  string(%d) "%s/glob_variation/wonder12345"
194  [2]=>
195  string(%d) "%s/glob_variation/wonder;123456"
196}
197
198-- Iteration 3 --
199array(2) {
200  [0]=>
201  string(%d) "%s/glob_variation/wonder12345"
202  [1]=>
203  string(%d) "%s/glob_variation/wonder;123456"
204}
205array(2) {
206  [0]=>
207  string(%d) "%s/glob_variation/wonder12345"
208  [1]=>
209  string(%d) "%s/glob_variation/wonder;123456"
210}
211array(2) {
212  [0]=>
213  string(%d) "%s"
214  [1]=>
215  string(%d) "%s"
216}
217array(2) {
218  [0]=>
219  string(%d) "%s/glob_variation/wonder12345"
220  [1]=>
221  string(%d) "%s/glob_variation/wonder;123456"
222}
223array(2) {
224  [0]=>
225  string(%d) "%s/glob_variation/wonder12345"
226  [1]=>
227  string(%d) "%s/glob_variation/wonder;123456"
228}
229array(2) {
230  [0]=>
231  string(%d) "%s/glob_variation/wonder12345"
232  [1]=>
233  string(%d) "%s/glob_variation/wonder;123456"
234}
235
236-- Iteration 4 --
237array(0) {
238}
239array(0) {
240}
241array(0) {
242}
243array(1) {
244  [0]=>
245  string(%d) "%s/glob_variation/*der5"
246}
247array(0) {
248}
249array(0) {
250}
251
252-- Iteration 5 --
253array(0) {
254}
255array(0) {
256}
257array(0) {
258}
259array(1) {
260  [0]=>
261  string(%d) "%s/glob_variation/??onder*"
262}
263array(0) {
264}
265array(0) {
266}
267
268-- Iteration 6 --
269array(3) {
270  [0]=>
271  string(%d) "%s/glob_variation/wonder"
272  [1]=>
273  string(%d) "%s/glob_variation/wonder12345"
274  [2]=>
275  string(%d) "%s/glob_variation/wonder;123456"
276}
277array(3) {
278  [0]=>
279  string(%d) "%s/glob_variation/wonder/"
280  [1]=>
281  string(%d) "%s/glob_variation/wonder12345"
282  [2]=>
283  string(%d) "%s/glob_variation/wonder;123456"
284}
285array(3) {
286  [0]=>
287  string(%d) "%s"
288  [1]=>
289  string(%d) "%s"
290  [2]=>
291  string(%d) "%s"
292}
293array(3) {
294  [0]=>
295  string(%d) "%s/glob_variation/wonder"
296  [1]=>
297  string(%d) "%s/glob_variation/wonder12345"
298  [2]=>
299  string(%d) "%s/glob_variation/wonder;123456"
300}
301array(3) {
302  [0]=>
303  string(%d) "%s/glob_variation/wonder"
304  [1]=>
305  string(%d) "%s/glob_variation/wonder12345"
306  [2]=>
307  string(%d) "%s/glob_variation/wonder;123456"
308}
309array(3) {
310  [0]=>
311  string(%d) "%s/glob_variation/wonder"
312  [1]=>
313  string(%d) "%s/glob_variation/wonder12345"
314  [2]=>
315  string(%d) "%s/glob_variation/wonder;123456"
316}
317
318-- Iteration 7 --
319array(0) {
320}
321array(0) {
322}
323array(0) {
324}
325array(1) {
326  [0]=>
327  string(%d) "%s/glob_variation/++onder*"
328}
329array(0) {
330}
331array(0) {
332}
333
334-- Iteration 8 --
335glob(): Argument #1 ($pattern) must not contain any null bytes
336
337-- Iteration 9 --
338array(0) {
339}
340array(0) {
341}
342array(0) {
343}
344array(1) {
345  [0]=>
346  string(%d) "$file_path/glob_variation/wonder5"
347}
348array(0) {
349}
350array(0) {
351}
352
353-- Iteration 10 --
354array(0) {
355}
356array(0) {
357}
358array(0) {
359}
360array(1) {
361  [0]=>
362  string(%d) "%s/glob_variation/?wonder?"
363}
364array(0) {
365}
366array(0) {
367}
368
369-- Iteration 11 --
370array(0) {
371}
372array(0) {
373}
374array(0) {
375}
376array(1) {
377  [0]=>
378  string(%d) "%s/glob_variation/wonder?"
379}
380array(0) {
381}
382array(0) {
383}
384
385-- Iteration 12 --
386array(0) {
387}
388array(0) {
389}
390array(0) {
391}
392array(1) {
393  [0]=>
394  string(%d) "1"
395}
396array(0) {
397}
398array(0) {
399}
400
401*** Testing glob() with pattern within braces ***
402array(1) {
403  [0]=>
404  string(%d) "%s/glob_variation/wonder12345"
405}
406
407*** Testing glob() on directories ***
408-- Iteration 1 --
409array(1) {
410  [0]=>
411  string(%d) "%s/glob_variation/wonder1"
412}
413-- Iteration 2 --
414array(1) {
415  [0]=>
416  string(%d) "%s/glob_variation/wonder1"
417}
418-- Iteration 3 --
419array(1) {
420  [0]=>
421  string(%d) "%s/glob_variation/wonder1"
422}
423-- Iteration 4 --
424array(0) {
425}
426-- Iteration 5 --
427array(0) {
428}
429-- Iteration 6 --
430array(1) {
431  [0]=>
432  string(%d) "%s/glob_variation/wonder1"
433}
434-- Iteration 7 --
435array(0) {
436}
437-- Iteration 8 --
438glob(): Argument #1 ($pattern) must not contain any null bytes
439-- Iteration 9 --
440array(0) {
441}
442-- Iteration 10 --
443array(0) {
444}
445-- Iteration 11 --
446array(1) {
447  [0]=>
448  string(%d) "%s/glob_variation/wonder1"
449}
450-- Iteration 12 --
451array(0) {
452}
453Done
454