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