1--TEST--
2Test chmod() function : second 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
23$filename = __FILE__ . ".tmp";
24$fd = fopen($filename, "w+");
25fclose($fd);
26
27//get an unset variable
28$unset_var = 10;
29unset ($unset_var);
30
31// define some classes
32class classWithToString
33{
34	public function __toString() {
35		return "Class A object";
36	}
37}
38
39class classWithoutToString
40{
41}
42
43// heredoc string
44$heredoc = <<<EOT
45hello world
46EOT;
47
48// add arrays
49$index_array = array (1, 2, 3);
50$assoc_array = array ('one' => 1, 'two' => 2);
51
52//array of values to iterate over
53$inputs = array(
54
55      // float data
56      'float 10.5' => 10.5,
57      'float -10.5' => -10.5,
58      'float 12.3456789000e10' => 12.3456789000e10,
59      'float -12.3456789000e10' => -12.3456789000e10,
60      'float .5' => .5,
61
62      // array data
63      'empty array' => array(),
64      'int indexed array' => $index_array,
65      'associative array' => $assoc_array,
66      'nested arrays' => array('foo', $index_array, $assoc_array),
67
68      // null data
69      'uppercase NULL' => NULL,
70      'lowercase null' => null,
71
72      // boolean data
73      'lowercase true' => true,
74      'lowercase false' =>false,
75      'uppercase TRUE' =>TRUE,
76      'uppercase FALSE' =>FALSE,
77
78      // empty data
79      'empty string DQ' => "",
80      'empty string SQ' => '',
81
82      // string data
83      'string DQ' => "string",
84      'string SQ' => 'string',
85      'mixed case string' => "sTrInG",
86      'heredoc' => $heredoc,
87
88      // object data
89      'instance of classWithToString' => new classWithToString(),
90      'instance of classWithoutToString' => new classWithoutToString(),
91
92      // undefined data
93      'undefined var' => @$undefined_var,
94
95      // unset data
96      'unset var' => @$unset_var,
97);
98
99// loop through each element of the array for mode
100
101foreach($inputs as $key =>$value) {
102      echo "\n--$key--\n";
103      var_dump( chmod($filename, $value) );
104};
105
106chmod($filename, 0777);
107unlink($filename);
108
109?>
110===DONE===
111--EXPECTF--
112*** Testing chmod() : usage variation ***
113
114--float 10.5--
115bool(true)
116
117--float -10.5--
118bool(true)
119
120--float 12.3456789000e10--
121bool(true)
122
123--float -12.3456789000e10--
124bool(true)
125
126--float .5--
127bool(true)
128
129--empty array--
130Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
131NULL
132
133--int indexed array--
134Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
135NULL
136
137--associative array--
138Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
139NULL
140
141--nested arrays--
142Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
143NULL
144
145--uppercase NULL--
146bool(true)
147
148--lowercase null--
149bool(true)
150
151--lowercase true--
152bool(true)
153
154--lowercase false--
155bool(true)
156
157--uppercase TRUE--
158bool(true)
159
160--uppercase FALSE--
161bool(true)
162
163--empty string DQ--
164Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
165NULL
166
167--empty string SQ--
168Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
169NULL
170
171--string DQ--
172Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
173NULL
174
175--string SQ--
176Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
177NULL
178
179--mixed case string--
180Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
181NULL
182
183--heredoc--
184Error: 2 - chmod() expects parameter 2 to be long, string given, %s(%d)
185NULL
186
187--instance of classWithToString--
188Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d)
189NULL
190
191--instance of classWithoutToString--
192Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d)
193NULL
194
195--undefined var--
196bool(true)
197
198--unset var--
199bool(true)
200===DONE===
201
202