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