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