1--TEST-- 2Test pathinfo() function: usage variations 3--FILE-- 4<?php 5echo "*** Testing pathinfo() with miscellaneous input arguments ***\n"; 6 7class object_temp { 8 public $url_var = "www.foo.com"; 9 var $html_var = "/var/html/testdir/example.html"; 10 var $dir_var = "/testdir/foo/test/"; 11 public $file_var = "/foo//symlink.link"; 12 var $number = 12345; 13} 14$obj = new object_temp(); 15 16$path_arr = array ( 17 "www.example.com", 18 "/testdir/foo//test/", 19 "../foo/test.link", 20 "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6/test.tmp", 21 2.345 22); 23 24$paths = array ( 25 /* pathname containing numeric string */ 26 0, 27 1234, 28 -1234, 29 2.3456, 30 31 /* pathname as boolean */ 32 TRUE, 33 FALSE, 34 35 /* pathname as an array */ 36 "./array(1, 2)", 37 "array( array(), null)", 38 39 /* pathname as spaces */ 40 " ", 41 ' ', 42 43 /* empty pathname */ 44 "", 45 '', 46 47 /* pathname as members of object */ 48 $obj->url_var, 49 $obj->html_var, 50 $obj->dir_var, 51 $obj->file_var, 52 $obj->number, 53 54 /* pathname as member of array */ 55 $path_arr[0], 56 $path_arr[1], 57 $path_arr[2], 58 $path_arr[3], 59 $path_arr[4] 60); 61 62$counter = 1; 63/* loop through $paths to test each $path in the above array */ 64foreach($paths as $path) { 65 echo "-- Iteration $counter --\n"; 66 var_dump( pathinfo($path) ); 67 var_dump( pathinfo($path, PATHINFO_DIRNAME) ); 68 var_dump( pathinfo($path, PATHINFO_BASENAME) ); 69 var_dump( pathinfo($path, PATHINFO_EXTENSION) ); 70 var_dump( pathinfo($path, PATHINFO_FILENAME) ); 71 $counter++; 72} 73 74echo "Done\n"; 75?> 76--EXPECT-- 77*** Testing pathinfo() with miscellaneous input arguments *** 78-- Iteration 1 -- 79array(3) { 80 ["dirname"]=> 81 string(1) "." 82 ["basename"]=> 83 string(1) "0" 84 ["filename"]=> 85 string(1) "0" 86} 87string(1) "." 88string(1) "0" 89string(0) "" 90string(1) "0" 91-- Iteration 2 -- 92array(3) { 93 ["dirname"]=> 94 string(1) "." 95 ["basename"]=> 96 string(4) "1234" 97 ["filename"]=> 98 string(4) "1234" 99} 100string(1) "." 101string(4) "1234" 102string(0) "" 103string(4) "1234" 104-- Iteration 3 -- 105array(3) { 106 ["dirname"]=> 107 string(1) "." 108 ["basename"]=> 109 string(5) "-1234" 110 ["filename"]=> 111 string(5) "-1234" 112} 113string(1) "." 114string(5) "-1234" 115string(0) "" 116string(5) "-1234" 117-- Iteration 4 -- 118array(4) { 119 ["dirname"]=> 120 string(1) "." 121 ["basename"]=> 122 string(6) "2.3456" 123 ["extension"]=> 124 string(4) "3456" 125 ["filename"]=> 126 string(1) "2" 127} 128string(1) "." 129string(6) "2.3456" 130string(4) "3456" 131string(1) "2" 132-- Iteration 5 -- 133array(3) { 134 ["dirname"]=> 135 string(1) "." 136 ["basename"]=> 137 string(1) "1" 138 ["filename"]=> 139 string(1) "1" 140} 141string(1) "." 142string(1) "1" 143string(0) "" 144string(1) "1" 145-- Iteration 6 -- 146array(2) { 147 ["basename"]=> 148 string(0) "" 149 ["filename"]=> 150 string(0) "" 151} 152string(0) "" 153string(0) "" 154string(0) "" 155string(0) "" 156-- Iteration 7 -- 157array(3) { 158 ["dirname"]=> 159 string(1) "." 160 ["basename"]=> 161 string(11) "array(1, 2)" 162 ["filename"]=> 163 string(11) "array(1, 2)" 164} 165string(1) "." 166string(11) "array(1, 2)" 167string(0) "" 168string(11) "array(1, 2)" 169-- Iteration 8 -- 170array(3) { 171 ["dirname"]=> 172 string(1) "." 173 ["basename"]=> 174 string(21) "array( array(), null)" 175 ["filename"]=> 176 string(21) "array( array(), null)" 177} 178string(1) "." 179string(21) "array( array(), null)" 180string(0) "" 181string(21) "array( array(), null)" 182-- Iteration 9 -- 183array(3) { 184 ["dirname"]=> 185 string(1) "." 186 ["basename"]=> 187 string(1) " " 188 ["filename"]=> 189 string(1) " " 190} 191string(1) "." 192string(1) " " 193string(0) "" 194string(1) " " 195-- Iteration 10 -- 196array(3) { 197 ["dirname"]=> 198 string(1) "." 199 ["basename"]=> 200 string(1) " " 201 ["filename"]=> 202 string(1) " " 203} 204string(1) "." 205string(1) " " 206string(0) "" 207string(1) " " 208-- Iteration 11 -- 209array(2) { 210 ["basename"]=> 211 string(0) "" 212 ["filename"]=> 213 string(0) "" 214} 215string(0) "" 216string(0) "" 217string(0) "" 218string(0) "" 219-- Iteration 12 -- 220array(2) { 221 ["basename"]=> 222 string(0) "" 223 ["filename"]=> 224 string(0) "" 225} 226string(0) "" 227string(0) "" 228string(0) "" 229string(0) "" 230-- Iteration 13 -- 231array(4) { 232 ["dirname"]=> 233 string(1) "." 234 ["basename"]=> 235 string(11) "www.foo.com" 236 ["extension"]=> 237 string(3) "com" 238 ["filename"]=> 239 string(7) "www.foo" 240} 241string(1) "." 242string(11) "www.foo.com" 243string(3) "com" 244string(7) "www.foo" 245-- Iteration 14 -- 246array(4) { 247 ["dirname"]=> 248 string(17) "/var/html/testdir" 249 ["basename"]=> 250 string(12) "example.html" 251 ["extension"]=> 252 string(4) "html" 253 ["filename"]=> 254 string(7) "example" 255} 256string(17) "/var/html/testdir" 257string(12) "example.html" 258string(4) "html" 259string(7) "example" 260-- Iteration 15 -- 261array(3) { 262 ["dirname"]=> 263 string(12) "/testdir/foo" 264 ["basename"]=> 265 string(4) "test" 266 ["filename"]=> 267 string(4) "test" 268} 269string(12) "/testdir/foo" 270string(4) "test" 271string(0) "" 272string(4) "test" 273-- Iteration 16 -- 274array(4) { 275 ["dirname"]=> 276 string(4) "/foo" 277 ["basename"]=> 278 string(12) "symlink.link" 279 ["extension"]=> 280 string(4) "link" 281 ["filename"]=> 282 string(7) "symlink" 283} 284string(4) "/foo" 285string(12) "symlink.link" 286string(4) "link" 287string(7) "symlink" 288-- Iteration 17 -- 289array(3) { 290 ["dirname"]=> 291 string(1) "." 292 ["basename"]=> 293 string(5) "12345" 294 ["filename"]=> 295 string(5) "12345" 296} 297string(1) "." 298string(5) "12345" 299string(0) "" 300string(5) "12345" 301-- Iteration 18 -- 302array(4) { 303 ["dirname"]=> 304 string(1) "." 305 ["basename"]=> 306 string(15) "www.example.com" 307 ["extension"]=> 308 string(3) "com" 309 ["filename"]=> 310 string(11) "www.example" 311} 312string(1) "." 313string(15) "www.example.com" 314string(3) "com" 315string(11) "www.example" 316-- Iteration 19 -- 317array(3) { 318 ["dirname"]=> 319 string(12) "/testdir/foo" 320 ["basename"]=> 321 string(4) "test" 322 ["filename"]=> 323 string(4) "test" 324} 325string(12) "/testdir/foo" 326string(4) "test" 327string(0) "" 328string(4) "test" 329-- Iteration 20 -- 330array(4) { 331 ["dirname"]=> 332 string(6) "../foo" 333 ["basename"]=> 334 string(9) "test.link" 335 ["extension"]=> 336 string(4) "link" 337 ["filename"]=> 338 string(4) "test" 339} 340string(6) "../foo" 341string(9) "test.link" 342string(4) "link" 343string(4) "test" 344-- Iteration 21 -- 345array(4) { 346 ["dirname"]=> 347 string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6" 348 ["basename"]=> 349 string(8) "test.tmp" 350 ["extension"]=> 351 string(3) "tmp" 352 ["filename"]=> 353 string(4) "test" 354} 355string(76) "./test/work/scratch/mydir/yourdir/ourdir/test1/test2/test3/test4/test5/test6" 356string(8) "test.tmp" 357string(3) "tmp" 358string(4) "test" 359-- Iteration 22 -- 360array(4) { 361 ["dirname"]=> 362 string(1) "." 363 ["basename"]=> 364 string(5) "2.345" 365 ["extension"]=> 366 string(3) "345" 367 ["filename"]=> 368 string(1) "2" 369} 370string(1) "." 371string(5) "2.345" 372string(3) "345" 373string(1) "2" 374Done 375