1--TEST--
2Test readfile() function : usage variation
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7/* Prototype  : int readfile(string filename [, bool use_include_path[, resource context]])
8 * Description: Output a file or a URL
9 * Source code: ext/standard/file.c
10 * Alias to functions:
11 */
12
13echo "*** Testing readfile() : 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 (if any)
25$filename = 'readFileVar4.tmp';
26$use_include_path = false;
27$h = fopen($filename,'wb');
28fwrite($h, "testing readfile");
29fclose($h);
30
31
32$fileRes = fopen(__FILE__, 'r');
33
34//get an unset variable
35$unset_var = 10;
36unset ($unset_var);
37
38// define some classes
39class classWithToString
40{
41	public function __toString() {
42		return "Class A object";
43	}
44}
45
46class classWithoutToString
47{
48}
49
50// heredoc string
51$heredoc = <<<EOT
52hello world
53EOT;
54
55// add arrays
56$index_array = array (1, 2, 3);
57$assoc_array = array ('one' => 1, 'two' => 2);
58
59//array of values to iterate over
60$inputs = array(
61
62      // int data
63      'int 0' => 0,
64      'int 1' => 1,
65      'int 12345' => 12345,
66      'int -12345' => -2345,
67
68      // float data
69      'float 10.5' => 10.5,
70      'float -10.5' => -10.5,
71      'float 12.3456789000e10' => 12.3456789000e10,
72      'float -12.3456789000e10' => -12.3456789000e10,
73      'float .5' => .5,
74
75      // array data
76      'empty array' => array(),
77      'int indexed array' => $index_array,
78      'associative array' => $assoc_array,
79      'nested arrays' => array('foo', $index_array, $assoc_array),
80
81      // null data
82      'uppercase NULL' => NULL,
83      'lowercase null' => null,
84
85      // boolean data
86      'lowercase true' => true,
87      'lowercase false' =>false,
88      'uppercase TRUE' =>TRUE,
89      'uppercase FALSE' =>FALSE,
90
91      // empty data
92      'empty string DQ' => "",
93      'empty string SQ' => '',
94
95      // string data
96      'string DQ' => "string",
97      'string SQ' => 'string',
98      'mixed case string' => "sTrInG",
99      'heredoc' => $heredoc,
100
101      // object data
102      'instance of classWithToString' => new classWithToString(),
103      'instance of classWithoutToString' => new classWithoutToString(),
104
105      // undefined data
106      'undefined var' => @$undefined_var,
107
108      // unset data
109      'unset var' => @$unset_var,
110
111      // file resource
112      'file resource' => $fileRes,
113);
114
115// loop through each element of the array for context
116
117foreach($inputs as $key =>$value) {
118      echo "\n--$key--\n";
119      $h = readfile($filename, $use_include_path, $value);
120      if ($h == false) {
121         echo "file not read\n";
122      }
123      else {
124         echo "\n";
125      }
126};
127
128unlink($filename);
129fclose($fileRes);
130
131?>
132===DONE===
133--EXPECTF--
134*** Testing readfile() : usage variation ***
135
136--int 0--
137Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d)
138file not read
139
140--int 1--
141Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d)
142file not read
143
144--int 12345--
145Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d)
146file not read
147
148--int -12345--
149Error: 2 - readfile() expects parameter 3 to be resource, integer given, %s(%d)
150file not read
151
152--float 10.5--
153Error: 2 - readfile() expects parameter 3 to be resource, float given, %s(%d)
154file not read
155
156--float -10.5--
157Error: 2 - readfile() expects parameter 3 to be resource, float given, %s(%d)
158file not read
159
160--float 12.3456789000e10--
161Error: 2 - readfile() expects parameter 3 to be resource, float given, %s(%d)
162file not read
163
164--float -12.3456789000e10--
165Error: 2 - readfile() expects parameter 3 to be resource, float given, %s(%d)
166file not read
167
168--float .5--
169Error: 2 - readfile() expects parameter 3 to be resource, float given, %s(%d)
170file not read
171
172--empty array--
173Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d)
174file not read
175
176--int indexed array--
177Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d)
178file not read
179
180--associative array--
181Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d)
182file not read
183
184--nested arrays--
185Error: 2 - readfile() expects parameter 3 to be resource, array given, %s(%d)
186file not read
187
188--uppercase NULL--
189testing readfile
190
191--lowercase null--
192testing readfile
193
194--lowercase true--
195Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d)
196file not read
197
198--lowercase false--
199Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d)
200file not read
201
202--uppercase TRUE--
203Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d)
204file not read
205
206--uppercase FALSE--
207Error: 2 - readfile() expects parameter 3 to be resource, boolean given, %s(%d)
208file not read
209
210--empty string DQ--
211Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
212file not read
213
214--empty string SQ--
215Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
216file not read
217
218--string DQ--
219Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
220file not read
221
222--string SQ--
223Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
224file not read
225
226--mixed case string--
227Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
228file not read
229
230--heredoc--
231Error: 2 - readfile() expects parameter 3 to be resource, string given, %s(%d)
232file not read
233
234--instance of classWithToString--
235Error: 2 - readfile() expects parameter 3 to be resource, object given, %s(%d)
236file not read
237
238--instance of classWithoutToString--
239Error: 2 - readfile() expects parameter 3 to be resource, object given, %s(%d)
240file not read
241
242--undefined var--
243testing readfile
244
245--unset var--
246testing readfile
247
248--file resource--
249Error: 2 - readfile(): supplied resource is not a valid Stream-Context resource, %s(%d)
250testing readfile
251===DONE===
252