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