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