1--TEST-- 2Test mkdir() function : usage variation: different types for mode 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only"); 7--FILE-- 8<?php 9/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) 10 * Description: Create a directory 11 * Source code: ext/standard/file.c 12 * Alias to functions: 13 */ 14 15echo "*** Testing mkdir() : usage variation ***\n"; 16 17// Define error handler 18function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 19 if (error_reporting() != 0) { 20 // report non-silenced errors 21 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 22 } 23} 24set_error_handler('test_error_handler'); 25 26// Initialise function arguments not being substituted (if any) 27$pathname = 'mkdirVar2.tmp'; 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 $h = mkdir($pathname, $value); 106 if ($h === true) { 107 echo "Directory created\n"; 108 rmdir($pathname); 109 } 110}; 111 112?> 113===DONE=== 114--EXPECTF-- 115*** Testing mkdir() : usage variation *** 116 117--float 10.5-- 118Directory created 119 120--float -10.5-- 121Directory created 122 123--float 12.3456789000e10-- 124Directory created 125 126--float -12.3456789000e10-- 127Directory created 128 129--float .5-- 130Directory created 131 132--empty array-- 133Error: 2 - mkdir() expects parameter 2 to be integer, array given, %s(%d) 134 135--int indexed array-- 136Error: 2 - mkdir() expects parameter 2 to be integer, array given, %s(%d) 137 138--associative array-- 139Error: 2 - mkdir() expects parameter 2 to be integer, array given, %s(%d) 140 141--nested arrays-- 142Error: 2 - mkdir() expects parameter 2 to be integer, array given, %s(%d) 143 144--uppercase NULL-- 145Directory created 146 147--lowercase null-- 148Directory created 149 150--lowercase true-- 151Directory created 152 153--lowercase false-- 154Directory created 155 156--uppercase TRUE-- 157Directory created 158 159--uppercase FALSE-- 160Directory created 161 162--empty string DQ-- 163Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 164 165--empty string SQ-- 166Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 167 168--string DQ-- 169Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 170 171--string SQ-- 172Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 173 174--mixed case string-- 175Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 176 177--heredoc-- 178Error: 2 - mkdir() expects parameter 2 to be integer, string given, %s(%d) 179 180--instance of classWithToString-- 181Error: 2 - mkdir() expects parameter 2 to be integer, object given, %s(%d) 182 183--instance of classWithoutToString-- 184Error: 2 - mkdir() expects parameter 2 to be integer, object given, %s(%d) 185 186--undefined var-- 187Directory created 188 189--unset var-- 190Directory created 191===DONE=== 192