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