1--TEST--
2Test file_get_contents() function : usage variation
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
7--FILE--
8<?php
9/* Prototype  : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
10 * Description: Read the entire file into a string
11 * Source code: ext/standard/file.c
12 * Alias to functions:
13 */
14
15echo "*** Testing file_get_contents() : usage variation ***\n";
16
17// Define error handler
18function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
19	if (error_reporting() != 0) {
20		// report non-silenced errors
21		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
22	}
23}
24set_error_handler('test_error_handler');
25
26// Initialise function arguments not being substituted (if any)
27$filename = 'FileGetContentsVar5.tmp';
28$absFile = dirname(__FILE__).'/'.$filename;
29$h = fopen($absFile,"w");
30fwrite($h, b"contents read");
31fclose($h);
32
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
112// loop through each element of the array for offset
113
114foreach($inputs as $key =>$value) {
115      echo "\n--$key--\n";
116      var_dump( file_get_contents($absFile, false, null, $value) );
117};
118
119unlink($absFile);
120
121?>
122===DONE===
123--EXPECTF--
124*** Testing file_get_contents() : usage variation ***
125
126--int 0--
127string(%d) "contents read"
128
129--int 1--
130string(%d) "ontents read"
131
132--int 12345--
133string(%d) ""
134
135--int -12345--
136string(%d) "contents read"
137
138--float 10.5--
139string(3) "ead"
140
141--float -10.5--
142string(%d) "contents read"
143
144--float 12.3456789000e10--
145string(%d) %s
146
147--float -12.3456789000e10--
148string(%d) %s
149
150--float .5--
151string(%d) "contents read"
152
153--empty array--
154Error: 2 - file_get_contents() expects parameter 4 to be integer, array given, %s(%d)
155NULL
156
157--int indexed array--
158Error: 2 - file_get_contents() expects parameter 4 to be integer, array given, %s(%d)
159NULL
160
161--associative array--
162Error: 2 - file_get_contents() expects parameter 4 to be integer, array given, %s(%d)
163NULL
164
165--nested arrays--
166Error: 2 - file_get_contents() expects parameter 4 to be integer, array given, %s(%d)
167NULL
168
169--uppercase NULL--
170string(%d) "contents read"
171
172--lowercase null--
173string(%d) "contents read"
174
175--lowercase true--
176string(12) "ontents read"
177
178--lowercase false--
179string(%d) "contents read"
180
181--uppercase TRUE--
182string(12) "ontents read"
183
184--uppercase FALSE--
185string(%d) "contents read"
186
187--empty string DQ--
188Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
189NULL
190
191--empty string SQ--
192Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
193NULL
194
195--string DQ--
196Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
197NULL
198
199--string SQ--
200Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
201NULL
202
203--mixed case string--
204Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
205NULL
206
207--heredoc--
208Error: 2 - file_get_contents() expects parameter 4 to be integer, %unicode_string_optional% given, %s(%d)
209NULL
210
211--instance of classWithToString--
212Error: 2 - file_get_contents() expects parameter 4 to be integer, object given, %s(%d)
213NULL
214
215--instance of classWithoutToString--
216Error: 2 - file_get_contents() expects parameter 4 to be integer, object given, %s(%d)
217NULL
218
219--undefined var--
220string(%d) "contents read"
221
222--unset var--
223string(%d) "contents read"
224===DONE===
225