1--TEST--
2Test chmod() function : first parameter variation
3--FILE--
4<?php
5/* Prototype  : bool chmod(string filename, int mode)
6 * Description: Change file mode
7 * Source code: ext/standard/filestat.c
8 * Alias to functions:
9 */
10
11echo "*** Testing chmod() : usage variation ***\n";
12
13// Define error handler
14function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
15	if (error_reporting() != 0) {
16		// report non-silenced errors
17		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
18	}
19}
20set_error_handler('test_error_handler');
21
22// Initialise function arguments not being substituted (if any)
23$mode = 0777;
24
25//get an unset variable
26$unset_var = 10;
27unset ($unset_var);
28
29// define some classes
30class classWithToString
31{
32	public function __toString() {
33		return "Class A object";
34	}
35}
36
37class classWithoutToString
38{
39}
40
41// heredoc string
42$heredoc = <<<EOT
43hello world
44EOT;
45
46// add arrays
47$index_array = array (1, 2, 3);
48$assoc_array = array ('one' => 1, 'two' => 2);
49
50//array of values to iterate over
51$inputs = array(
52
53      // int data
54      'int 0' => 0,
55      'int 1' => 1,
56      'int 12345' => 12345,
57      'int -12345' => -2345,
58
59      // float data
60      'float 10.5' => 10.5,
61      'float -10.5' => -10.5,
62      'float 12.3456789000e10' => 12.3456789000e10,
63      'float -12.3456789000e10' => -12.3456789000e10,
64      'float .5' => .5,
65
66      // array data
67      'empty array' => array(),
68      'int indexed array' => $index_array,
69      'associative array' => $assoc_array,
70      'nested arrays' => array('foo', $index_array, $assoc_array),
71
72      // null data
73      'uppercase NULL' => NULL,
74      'lowercase null' => null,
75
76      // boolean data
77      'lowercase true' => true,
78      'lowercase false' =>false,
79      'uppercase TRUE' =>TRUE,
80      'uppercase FALSE' =>FALSE,
81
82      // empty data
83      'empty string DQ' => "",
84      'empty string SQ' => '',
85
86      // object data
87      'instance of classWithToString' => new classWithToString(),
88      'instance of classWithoutToString' => new classWithoutToString(),
89
90      // undefined data
91      'undefined var' => @$undefined_var,
92
93      // unset data
94      'unset var' => @$unset_var,
95);
96
97// loop through each element of the array for filename
98
99foreach($inputs as $key =>$value) {
100      echo "\n--$key--\n";
101      var_dump( chmod($value, $mode) );
102};
103
104?>
105===DONE===
106--EXPECTF--
107*** Testing chmod() : usage variation ***
108
109--int 0--
110Error: 2 - chmod(): No such file or directory, %s(%d)
111bool(false)
112
113--int 1--
114Error: 2 - chmod(): No such file or directory, %s(%d)
115bool(false)
116
117--int 12345--
118Error: 2 - chmod(): No such file or directory, %s(%d)
119bool(false)
120
121--int -12345--
122Error: 2 - chmod(): No such file or directory, %s(%d)
123bool(false)
124
125--float 10.5--
126Error: 2 - chmod(): No such file or directory, %s(%d)
127bool(false)
128
129--float -10.5--
130Error: 2 - chmod(): No such file or directory, %s(%d)
131bool(false)
132
133--float 12.3456789000e10--
134Error: 2 - chmod(): No such file or directory, %s(%d)
135bool(false)
136
137--float -12.3456789000e10--
138Error: 2 - chmod(): No such file or directory, %s(%d)
139bool(false)
140
141--float .5--
142Error: 2 - chmod(): No such file or directory, %s(%d)
143bool(false)
144
145--empty array--
146Error: 2 - chmod() expects parameter 1 to be a valid path, array given, %s(%d)
147NULL
148
149--int indexed array--
150Error: 2 - chmod() expects parameter 1 to be a valid path, array given, %s(%d)
151NULL
152
153--associative array--
154Error: 2 - chmod() expects parameter 1 to be a valid path, array given, %s(%d)
155NULL
156
157--nested arrays--
158Error: 2 - chmod() expects parameter 1 to be a valid path, array given, %s(%d)
159NULL
160
161--uppercase NULL--
162Error: 2 - chmod(): %s, %s(%d)
163bool(false)
164
165--lowercase null--
166Error: 2 - chmod(): %s, %s(%d)
167bool(false)
168
169--lowercase true--
170Error: 2 - chmod(): No such file or directory, %s(%d)
171bool(false)
172
173--lowercase false--
174Error: 2 - chmod(): %s, %s(%d)
175bool(false)
176
177--uppercase TRUE--
178Error: 2 - chmod(): No such file or directory, %s(%d)
179bool(false)
180
181--uppercase FALSE--
182Error: 2 - chmod(): %s, %s(%d)
183bool(false)
184
185--empty string DQ--
186Error: 2 - chmod(): %s, %s(%d)
187bool(false)
188
189--empty string SQ--
190Error: 2 - chmod(): %s, %s(%d)
191bool(false)
192
193--instance of classWithToString--
194Error: 2 - chmod(): No such file or directory, %s(%d)
195bool(false)
196
197--instance of classWithoutToString--
198Error: 2 - chmod() expects parameter 1 to be a valid path, object given, %s(%d)
199NULL
200
201--undefined var--
202Error: 2 - chmod(): %s, %s(%d)
203bool(false)
204
205--unset var--
206Error: 2 - chmod(): %s, %s(%d)
207bool(false)
208===DONE===
209
210