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