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