1--TEST--
2Test scandir() function : usage variations - different data types as $dir arg
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 scandir(string $dir [, int $sorting_order [, resource $context]])
12 * Description: List files & directories inside the specified path
13 * Source code: ext/standard/dir.c
14 */
15
16/*
17 * Pass different data types as $dir argument to test behaviour of scandir()
18 */
19
20echo "*** Testing scandir() : usage variations ***\n";
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// get a class
27class classA
28{
29  public function __toString() {
30    return "Class A object";
31  }
32}
33
34// heredoc string
35$heredoc = <<<EOT
36hello world
37EOT;
38
39// get a resource variable
40$fp = fopen(__FILE__, "r");
41
42// unexpected values to be passed to $dir argument
43$inputs = array(
44
45       // int data
46/*1*/  0,
47       1,
48       12345,
49       -2345,
50
51       // float data
52/*5*/  10.5,
53       -10.5,
54       12.3456789000e10,
55       12.3456789000E-10,
56       .5,
57
58       // null data
59/*10*/ NULL,
60       null,
61
62       // boolean data
63/*12*/ true,
64       false,
65       TRUE,
66       FALSE,
67
68       // empty data
69/*16*/ "",
70       '',
71       array(),
72
73       // string data
74/*19*/ "string",
75       'string',
76       $heredoc,
77
78       // object data
79/*22*/ new classA(),
80
81       // undefined data
82/*23*/ @$undefined_var,
83
84       // unset data
85/*24*/ @$unset_var,
86
87       // resource variable
88/*25*/ $fp
89);
90
91// loop through each element of $inputs to check the behavior of scandir()
92$iterator = 1;
93foreach($inputs as $input) {
94  echo "\n-- Iteration $iterator --\n";
95  var_dump( scandir($input) );
96  $iterator++;
97};
98
99fclose($fp);
100?>
101===DONE===
102--EXPECTF--
103*** Testing scandir() : usage variations ***
104
105-- Iteration 1 --
106
107Warning: scandir(0): failed to open dir: %s in %s on line %d
108
109Warning: scandir(): (errno %d): %s in %s on line %d
110bool(false)
111
112-- Iteration 2 --
113
114Warning: scandir(1): failed to open dir: %s in %s on line %d
115
116Warning: scandir(): (errno %d): %s in %s on line %d
117bool(false)
118
119-- Iteration 3 --
120
121Warning: scandir(12345): failed to open dir: %s in %s on line %d
122
123Warning: scandir(): (errno %d): %s in %s on line %d
124bool(false)
125
126-- Iteration 4 --
127
128Warning: scandir(-2345): failed to open dir: %s in %s on line %d
129
130Warning: scandir(): (errno %d): %s in %s on line %d
131bool(false)
132
133-- Iteration 5 --
134
135Warning: scandir(10.5): failed to open dir: %s in %s on line %d
136
137Warning: scandir(): (errno %d): %s in %s on line %d
138bool(false)
139
140-- Iteration 6 --
141
142Warning: scandir(-10.5): failed to open dir: %s in %s on line %d
143
144Warning: scandir(): (errno %d): %s in %s on line %d
145bool(false)
146
147-- Iteration 7 --
148
149Warning: scandir(123456789000): failed to open dir: %s in %s on line %d
150
151Warning: scandir(): (errno %d): %s in %s on line %d
152bool(false)
153
154-- Iteration 8 --
155
156Warning: scandir(1.23456789E-9): failed to open dir: %s in %s on line %d
157
158Warning: scandir(): (errno %d): %s in %s on line %d
159bool(false)
160
161-- Iteration 9 --
162
163Warning: scandir(0.5): failed to open dir: %s in %s on line %d
164
165Warning: scandir(): (errno %d): %s in %s on line %d
166bool(false)
167
168-- Iteration 10 --
169
170Warning: scandir(): Directory name cannot be empty in %s on line %d
171bool(false)
172
173-- Iteration 11 --
174
175Warning: scandir(): Directory name cannot be empty in %s on line %d
176bool(false)
177
178-- Iteration 12 --
179
180Warning: scandir(1): failed to open dir: %s in %s on line %d
181
182Warning: scandir(): (errno %d): %s in %s on line %d
183bool(false)
184
185-- Iteration 13 --
186
187Warning: scandir(): Directory name cannot be empty in %s on line %d
188bool(false)
189
190-- Iteration 14 --
191
192Warning: scandir(1): failed to open dir: %s in %s on line %d
193
194Warning: scandir(): (errno %d): %s in %s on line %d
195bool(false)
196
197-- Iteration 15 --
198
199Warning: scandir(): Directory name cannot be empty in %s on line %d
200bool(false)
201
202-- Iteration 16 --
203
204Warning: scandir(): Directory name cannot be empty in %s on line %d
205bool(false)
206
207-- Iteration 17 --
208
209Warning: scandir(): Directory name cannot be empty in %s on line %d
210bool(false)
211
212-- Iteration 18 --
213
214Warning: scandir() expects parameter 1 to be string, array given in %s on line %d
215NULL
216
217-- Iteration 19 --
218
219Warning: scandir(string): failed to open dir: %s in %s on line %d
220
221Warning: scandir(): (errno %d): %s in %s on line %d
222bool(false)
223
224-- Iteration 20 --
225
226Warning: scandir(string): failed to open dir: %s in %s on line %d
227
228Warning: scandir(): (errno %d): %s in %s on line %d
229bool(false)
230
231-- Iteration 21 --
232
233Warning: scandir(hello world): failed to open dir: %s in %s on line %d
234
235Warning: scandir(): (errno %d): %s in %s on line %d
236bool(false)
237
238-- Iteration 22 --
239
240Warning: scandir(Class A object): failed to open dir: %s in %s on line %d
241
242Warning: scandir(): (errno %d): %s in %s on line %d
243bool(false)
244
245-- Iteration 23 --
246
247Warning: scandir(): Directory name cannot be empty in %s on line %d
248bool(false)
249
250-- Iteration 24 --
251
252Warning: scandir(): Directory name cannot be empty in %s on line %d
253bool(false)
254
255-- Iteration 25 --
256
257Warning: scandir() expects parameter 1 to be string, resource given in %s on line %d
258NULL
259===DONE===
260