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