1--TEST--
2Test file() function : second parameter variation
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
5--FILE--
6<?php
7/* Prototype  : array file(string filename [, int flags[, resource context]])
8 * Description: Read entire file into an array
9 * Source code: ext/standard/file.c
10 * Alias to functions:
11 */
12
13echo "*** Testing file() : usage variation ***\n";
14
15// Define error handler
16function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
17	if (error_reporting() != 0) {
18		// report non-silenced errors
19		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
20	}
21}
22set_error_handler('test_error_handler');
23
24// Initialise function arguments not being substituted
25$filename = __FILE__ . ".tmp";
26$fd = fopen($filename, "w+");
27fwrite($fd, "Line 1\nLine 2\nLine 3");
28fclose($fd);
29
30$context = stream_context_create();
31
32
33//get an unset variable
34$unset_var = 10;
35unset ($unset_var);
36
37// define some classes
38class classWithToString
39{
40	public function __toString() {
41		return "Class A object";
42	}
43}
44
45class classWithoutToString
46{
47}
48
49// heredoc string
50$heredoc = <<<EOT
51hello world
52EOT;
53
54// add arrays
55$index_array = array (1, 2, 3);
56$assoc_array = array ('one' => 1, 'two' => 2);
57
58//array of values to iterate over
59$inputs = array(
60
61      // float data
62      'float 10.5' => 10.5,
63      'float -10.5' => -10.5,
64      'float 12.3456789000e10' => 12.3456789000e10,
65      'float -12.3456789000e10' => -12.3456789000e10,
66      'float .5' => .5,
67
68      // array data
69      'empty array' => array(),
70      'int indexed array' => $index_array,
71      'associative array' => $assoc_array,
72      'nested arrays' => array('foo', $index_array, $assoc_array),
73
74      // null data
75      'uppercase NULL' => NULL,
76      'lowercase null' => null,
77
78      // boolean data
79      'lowercase true' => true,
80      'lowercase false' =>false,
81      'uppercase TRUE' =>TRUE,
82      'uppercase FALSE' =>FALSE,
83
84      // empty data
85      'empty string DQ' => "",
86      'empty string SQ' => '',
87
88      // string data
89      'string DQ' => "string",
90      'string SQ' => 'string',
91      'mixed case string' => "sTrInG",
92      'heredoc' => $heredoc,
93
94      // object data
95      'instance of classWithToString' => new classWithToString(),
96      'instance of classWithoutToString' => new classWithoutToString(),
97
98      // undefined data
99      'undefined var' => @$undefined_var,
100
101      // unset data
102      'unset var' => @$unset_var,
103);
104
105// loop through each element of the array for flags
106
107foreach($inputs as $key =>$value) {
108      echo "\n--$key--\n";
109      var_dump( file($filename, $value, $context) );
110};
111
112unlink(__FILE__ . ".tmp");
113
114?>
115===DONE===
116--EXPECTF--
117*** Testing file() : usage variation ***
118
119--float 10.5--
120array(3) {
121  [0]=>
122  string(6) "Line 1"
123  [1]=>
124  string(6) "Line 2"
125  [2]=>
126  string(6) "Line 3"
127}
128
129--float -10.5--
130Error: 2 - file(): '-10' flag is not supported, %s(%d)
131bool(false)
132
133--float 12.3456789000e10--
134Error: 2 - file(): '%i' flag is not supported, %s(%d)
135bool(false)
136
137--float -12.3456789000e10--
138Error: 2 - file(): '%i' flag is not supported, %s(%d)
139bool(false)
140
141--float .5--
142array(3) {
143  [0]=>
144  string(7) "Line 1
145"
146  [1]=>
147  string(7) "Line 2
148"
149  [2]=>
150  string(6) "Line 3"
151}
152
153--empty array--
154Error: 2 - file() expects parameter 2 to be integer, array given, %s(%d)
155NULL
156
157--int indexed array--
158Error: 2 - file() expects parameter 2 to be integer, array given, %s(%d)
159NULL
160
161--associative array--
162Error: 2 - file() expects parameter 2 to be integer, array given, %s(%d)
163NULL
164
165--nested arrays--
166Error: 2 - file() expects parameter 2 to be integer, array given, %s(%d)
167NULL
168
169--uppercase NULL--
170array(3) {
171  [0]=>
172  string(7) "Line 1
173"
174  [1]=>
175  string(7) "Line 2
176"
177  [2]=>
178  string(6) "Line 3"
179}
180
181--lowercase null--
182array(3) {
183  [0]=>
184  string(7) "Line 1
185"
186  [1]=>
187  string(7) "Line 2
188"
189  [2]=>
190  string(6) "Line 3"
191}
192
193--lowercase true--
194array(3) {
195  [0]=>
196  string(7) "Line 1
197"
198  [1]=>
199  string(7) "Line 2
200"
201  [2]=>
202  string(6) "Line 3"
203}
204
205--lowercase false--
206array(3) {
207  [0]=>
208  string(7) "Line 1
209"
210  [1]=>
211  string(7) "Line 2
212"
213  [2]=>
214  string(6) "Line 3"
215}
216
217--uppercase TRUE--
218array(3) {
219  [0]=>
220  string(7) "Line 1
221"
222  [1]=>
223  string(7) "Line 2
224"
225  [2]=>
226  string(6) "Line 3"
227}
228
229--uppercase FALSE--
230array(3) {
231  [0]=>
232  string(7) "Line 1
233"
234  [1]=>
235  string(7) "Line 2
236"
237  [2]=>
238  string(6) "Line 3"
239}
240
241--empty string DQ--
242Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
243NULL
244
245--empty string SQ--
246Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
247NULL
248
249--string DQ--
250Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
251NULL
252
253--string SQ--
254Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
255NULL
256
257--mixed case string--
258Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
259NULL
260
261--heredoc--
262Error: 2 - file() expects parameter 2 to be integer, string given, %s(%d)
263NULL
264
265--instance of classWithToString--
266Error: 2 - file() expects parameter 2 to be integer, object given, %s(%d)
267NULL
268
269--instance of classWithoutToString--
270Error: 2 - file() expects parameter 2 to be integer, object given, %s(%d)
271NULL
272
273--undefined var--
274array(3) {
275  [0]=>
276  string(7) "Line 1
277"
278  [1]=>
279  string(7) "Line 2
280"
281  [2]=>
282  string(6) "Line 3"
283}
284
285--unset var--
286array(3) {
287  [0]=>
288  string(7) "Line 1
289"
290  [1]=>
291  string(7) "Line 2
292"
293  [2]=>
294  string(6) "Line 3"
295}
296===DONE===
297