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