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