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