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