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