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