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