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