1--TEST-- 2Test scandir() function : usage variations - diff data types as $sorting_order arg 3--FILE-- 4<?php 5/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) 6 * Description: List files & directories inside the specified path 7 * Source code: ext/standard/dir.c 8 */ 9 10/* 11 * Pass different data types as $sorting_order argument to test how scandir() behaves 12 */ 13 14echo "*** Testing scandir() : usage variations ***\n"; 15 16// Initialise function arguments not being substituted 17$dir = dirname(__FILE__) . '/scandir_variation2'; 18mkdir($dir); 19 20//get an unset variable 21$unset_var = 10; 22unset ($unset_var); 23 24// get a class 25class classA 26{ 27 public function __toString() { 28 return "Class A object"; 29 } 30} 31 32// heredoc string 33$heredoc = <<<EOT 34hello world 35EOT; 36 37// get a resource variable 38$fp = fopen(__FILE__, "r"); 39 40// unexpected values to be passed to $sorting_order argument 41$inputs = array( 42 43 // int data 44/*1*/ 0, 45 1, 46 12345, 47 -2345, 48 49 // float data 50/*5*/ 10.5, 51 -10.5, 52 12.3456789000e10, 53 12.3456789000E-10, 54 .5, 55 56 // null data 57/*10*/ NULL, 58 null, 59 60 // boolean data 61/*12*/ true, 62 false, 63 TRUE, 64 FALSE, 65 66 // empty data 67/*16*/ "", 68 '', 69 array(), 70 71 // string data 72/*19*/ "string", 73 'string', 74 $heredoc, 75 76 // object data 77/*22*/ new classA(), 78 79 // undefined data 80/*23*/ @$undefined_var, 81 82 // unset data 83/*24*/ @$unset_var, 84 85 // resource variable 86/*25*/ $fp 87); 88 89// loop through each element of $inputs to check the behavior of scandir() 90$iterator = 1; 91foreach($inputs as $input) { 92 echo "\n-- Iteration $iterator --\n"; 93 var_dump( scandir($dir, $input) ); 94 $iterator++; 95}; 96 97fclose($fp); 98?> 99===DONE=== 100--CLEAN-- 101<?php 102$dir = dirname(__FILE__) . '/scandir_variation2'; 103rmdir($dir); 104?> 105--EXPECTF-- 106*** Testing scandir() : usage variations *** 107 108-- Iteration 1 -- 109array(2) { 110 [0]=> 111 string(1) "." 112 [1]=> 113 string(2) ".." 114} 115 116-- Iteration 2 -- 117array(2) { 118 [0]=> 119 string(2) ".." 120 [1]=> 121 string(1) "." 122} 123 124-- Iteration 3 -- 125array(2) { 126 [0]=> 127 string(2) ".." 128 [1]=> 129 string(1) "." 130} 131 132-- Iteration 4 -- 133array(2) { 134 [0]=> 135 string(2) ".." 136 [1]=> 137 string(1) "." 138} 139 140-- Iteration 5 -- 141array(2) { 142 [0]=> 143 string(2) ".." 144 [1]=> 145 string(1) "." 146} 147 148-- Iteration 6 -- 149array(2) { 150 [0]=> 151 string(2) ".." 152 [1]=> 153 string(1) "." 154} 155 156-- Iteration 7 -- 157array(2) { 158 [0]=> 159 string(2) ".." 160 [1]=> 161 string(1) "." 162} 163 164-- Iteration 8 -- 165array(2) { 166 [0]=> 167 string(1) "." 168 [1]=> 169 string(2) ".." 170} 171 172-- Iteration 9 -- 173array(2) { 174 [0]=> 175 string(1) "." 176 [1]=> 177 string(2) ".." 178} 179 180-- Iteration 10 -- 181array(2) { 182 [0]=> 183 string(1) "." 184 [1]=> 185 string(2) ".." 186} 187 188-- Iteration 11 -- 189array(2) { 190 [0]=> 191 string(1) "." 192 [1]=> 193 string(2) ".." 194} 195 196-- Iteration 12 -- 197array(2) { 198 [0]=> 199 string(2) ".." 200 [1]=> 201 string(1) "." 202} 203 204-- Iteration 13 -- 205array(2) { 206 [0]=> 207 string(1) "." 208 [1]=> 209 string(2) ".." 210} 211 212-- Iteration 14 -- 213array(2) { 214 [0]=> 215 string(2) ".." 216 [1]=> 217 string(1) "." 218} 219 220-- Iteration 15 -- 221array(2) { 222 [0]=> 223 string(1) "." 224 [1]=> 225 string(2) ".." 226} 227 228-- Iteration 16 -- 229 230Warning: scandir() expects parameter 2 to be long, string given in %s on line %d 231NULL 232 233-- Iteration 17 -- 234 235Warning: scandir() expects parameter 2 to be long, string given in %s on line %d 236NULL 237 238-- Iteration 18 -- 239 240Warning: scandir() expects parameter 2 to be long, array given in %s on line %d 241NULL 242 243-- Iteration 19 -- 244 245Warning: scandir() expects parameter 2 to be long, string given in %s on line %d 246NULL 247 248-- Iteration 20 -- 249 250Warning: scandir() expects parameter 2 to be long, string given in %s on line %d 251NULL 252 253-- Iteration 21 -- 254 255Warning: scandir() expects parameter 2 to be long, string given in %s on line %d 256NULL 257 258-- Iteration 22 -- 259 260Warning: scandir() expects parameter 2 to be long, object given in %s on line %d 261NULL 262 263-- Iteration 23 -- 264array(2) { 265 [0]=> 266 string(1) "." 267 [1]=> 268 string(2) ".." 269} 270 271-- Iteration 24 -- 272array(2) { 273 [0]=> 274 string(1) "." 275 [1]=> 276 string(2) ".." 277} 278 279-- Iteration 25 -- 280 281Warning: scandir() expects parameter 2 to be long, resource given in %s on line %d 282NULL 283===DONE=== 284