1--TEST--
2Test scandir() function : usage variations - diff data types as $sorting_order arg
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
5--FILE--
6<?php
7/* Prototype  : array scandir(string $dir [, int $sorting_order [, resource $context]])
8 * Description: List files & directories inside the specified path
9 * Source code: ext/standard/dir.c
10 */
11
12/*
13 * Pass different data types as $sorting_order argument to test how scandir() behaves
14 */
15
16echo "*** Testing scandir() : usage variations ***\n";
17
18// Initialise function arguments not being substituted
19$dir = dirname(__FILE__) . '/scandir_variation2';
20mkdir($dir);
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 $sorting_order 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($dir, $input) );
96  $iterator++;
97};
98
99fclose($fp);
100?>
101===DONE===
102--CLEAN--
103<?php
104$dir = dirname(__FILE__) . '/scandir_variation2';
105rmdir($dir);
106?>
107--EXPECTF--
108*** Testing scandir() : usage variations ***
109
110-- Iteration 1 --
111array(2) {
112  [0]=>
113  string(1) "."
114  [1]=>
115  string(2) ".."
116}
117
118-- Iteration 2 --
119array(2) {
120  [0]=>
121  string(2) ".."
122  [1]=>
123  string(1) "."
124}
125
126-- Iteration 3 --
127array(2) {
128  [0]=>
129  string(2) ".."
130  [1]=>
131  string(1) "."
132}
133
134-- Iteration 4 --
135array(2) {
136  [0]=>
137  string(2) ".."
138  [1]=>
139  string(1) "."
140}
141
142-- Iteration 5 --
143array(2) {
144  [0]=>
145  string(2) ".."
146  [1]=>
147  string(1) "."
148}
149
150-- Iteration 6 --
151array(2) {
152  [0]=>
153  string(2) ".."
154  [1]=>
155  string(1) "."
156}
157
158-- Iteration 7 --
159array(2) {
160  [0]=>
161  string(2) ".."
162  [1]=>
163  string(1) "."
164}
165
166-- Iteration 8 --
167array(2) {
168  [0]=>
169  string(1) "."
170  [1]=>
171  string(2) ".."
172}
173
174-- Iteration 9 --
175array(2) {
176  [0]=>
177  string(1) "."
178  [1]=>
179  string(2) ".."
180}
181
182-- Iteration 10 --
183array(2) {
184  [0]=>
185  string(1) "."
186  [1]=>
187  string(2) ".."
188}
189
190-- Iteration 11 --
191array(2) {
192  [0]=>
193  string(1) "."
194  [1]=>
195  string(2) ".."
196}
197
198-- Iteration 12 --
199array(2) {
200  [0]=>
201  string(2) ".."
202  [1]=>
203  string(1) "."
204}
205
206-- Iteration 13 --
207array(2) {
208  [0]=>
209  string(1) "."
210  [1]=>
211  string(2) ".."
212}
213
214-- Iteration 14 --
215array(2) {
216  [0]=>
217  string(2) ".."
218  [1]=>
219  string(1) "."
220}
221
222-- Iteration 15 --
223array(2) {
224  [0]=>
225  string(1) "."
226  [1]=>
227  string(2) ".."
228}
229
230-- Iteration 16 --
231
232Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d
233NULL
234
235-- Iteration 17 --
236
237Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d
238NULL
239
240-- Iteration 18 --
241
242Warning: scandir() expects parameter 2 to be integer, array given in %s on line %d
243NULL
244
245-- Iteration 19 --
246
247Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d
248NULL
249
250-- Iteration 20 --
251
252Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d
253NULL
254
255-- Iteration 21 --
256
257Warning: scandir() expects parameter 2 to be integer, string given in %s on line %d
258NULL
259
260-- Iteration 22 --
261
262Warning: scandir() expects parameter 2 to be integer, object given in %s on line %d
263NULL
264
265-- Iteration 23 --
266array(2) {
267  [0]=>
268  string(1) "."
269  [1]=>
270  string(2) ".."
271}
272
273-- Iteration 24 --
274array(2) {
275  [0]=>
276  string(1) "."
277  [1]=>
278  string(2) ".."
279}
280
281-- Iteration 25 --
282
283Warning: scandir() expects parameter 2 to be integer, resource given in %s on line %d
284NULL
285===DONE===
286