1--TEST-- 2Test mkdir() function : usage variation: different types for context 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype : bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]]) 8 * Description: Create a directory 9 * Source code: ext/standard/file.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing mkdir() : 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 (if any) 25$pathname = 'mkdirVar4.tmp'; 26$mode = 0777; 27$recursive = false; 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$fileRes = fopen(__FILE__,'r'); 55 56//array of values to iterate over 57$inputs = array( 58 59 // int data 60 'int 0' => 0, 61 'int 1' => 1, 62 'int 12345' => 12345, 63 'int -12345' => -2345, 64 65 // float data 66 'float 10.5' => 10.5, 67 'float -10.5' => -10.5, 68 'float 12.3456789000e10' => 12.3456789000e10, 69 'float -12.3456789000e10' => -12.3456789000e10, 70 'float .5' => .5, 71 72 // array data 73 'empty array' => array(), 74 'int indexed array' => $index_array, 75 'associative array' => $assoc_array, 76 'nested arrays' => array('foo', $index_array, $assoc_array), 77 78 // null data 79 'uppercase NULL' => NULL, 80 'lowercase null' => null, 81 82 // boolean data 83 'lowercase true' => true, 84 'lowercase false' =>false, 85 'uppercase TRUE' =>TRUE, 86 'uppercase FALSE' =>FALSE, 87 88 // empty data 89 'empty string DQ' => "", 90 'empty string SQ' => '', 91 92 // string data 93 'string DQ' => "string", 94 'string SQ' => 'string', 95 'mixed case string' => "sTrInG", 96 'heredoc' => $heredoc, 97 98 // object data 99 'instance of classWithToString' => new classWithToString(), 100 'instance of classWithoutToString' => new classWithoutToString(), 101 102 // undefined data 103 'undefined var' => @$undefined_var, 104 105 // unset data 106 'unset var' => @$unset_var, 107 108 // non stream context resource 109 'file resource' => $fileRes, 110); 111 112// loop through each element of the array for context 113 114foreach($inputs as $key =>$value) { 115 echo "\n--$key--\n"; 116 $h = mkdir($pathname, $mode, $recursive, $value); 117 if ($h === true) { 118 echo "Directory created\n"; 119 rmdir($pathname); 120 } 121}; 122 123fclose($fileRes); 124 125?> 126===DONE=== 127--EXPECTF-- 128*** Testing mkdir() : usage variation *** 129 130--int 0-- 131Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) 132 133--int 1-- 134Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) 135 136--int 12345-- 137Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) 138 139--int -12345-- 140Error: 2 - mkdir() expects parameter 4 to be resource, integer given, %s(%d) 141 142--float 10.5-- 143Error: 2 - mkdir() expects parameter 4 to be resource, float given, %s(%d) 144 145--float -10.5-- 146Error: 2 - mkdir() expects parameter 4 to be resource, float given, %s(%d) 147 148--float 12.3456789000e10-- 149Error: 2 - mkdir() expects parameter 4 to be resource, float given, %s(%d) 150 151--float -12.3456789000e10-- 152Error: 2 - mkdir() expects parameter 4 to be resource, float given, %s(%d) 153 154--float .5-- 155Error: 2 - mkdir() expects parameter 4 to be resource, float given, %s(%d) 156 157--empty array-- 158Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) 159 160--int indexed array-- 161Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) 162 163--associative array-- 164Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) 165 166--nested arrays-- 167Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) 168 169--uppercase NULL-- 170Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) 171 172--lowercase null-- 173Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) 174 175--lowercase true-- 176Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) 177 178--lowercase false-- 179Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) 180 181--uppercase TRUE-- 182Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) 183 184--uppercase FALSE-- 185Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) 186 187--empty string DQ-- 188Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 189 190--empty string SQ-- 191Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 192 193--string DQ-- 194Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 195 196--string SQ-- 197Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 198 199--mixed case string-- 200Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 201 202--heredoc-- 203Error: 2 - mkdir() expects parameter 4 to be resource, string given, %s(%d) 204 205--instance of classWithToString-- 206Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) 207 208--instance of classWithoutToString-- 209Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) 210 211--undefined var-- 212Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) 213 214--unset var-- 215Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) 216 217--file resource-- 218Error: 2 - mkdir(): supplied resource is not a valid Stream-Context resource, %s(%d) 219Directory created 220===DONE=== 221