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