1--TEST-- 2Test dirname() function : usage variations 3--FILE-- 4<?php 5/* Prototype: string dirname ( string $path ); 6 Description: Returns directory name component of path. 7*/ 8class temp 9{ 10 function __toString() { 11 return "Object"; 12 } 13} 14 15$file_path_variations = array ( 16 /* home dir shortcut char */ 17 "~/home/user/bar", 18 "~/home/user/bar/", 19 "~/home/user/bar.tar", 20 "~/home/user/bar.tar/", 21 22 /* with hotname:dir notation */ 23 "hostname:/home/user/bar.tar", 24 "hostname:/home/user/tbar.gz/", 25 "hostname:/home/user/My Pics.gz", 26 "hostname:/home/user/My Pics.gz/", 27 "hostname:/home/user/My Pics/", 28 "hostname:/home/user/My Pics", 29 30 /* path containing numeric string */ 31 "10.5", 32 "/10.5", 33 "/10.5/", 34 "10.5/", 35 "10/10.gz", 36 '0', 37 "0", 38 39 /* object */ 40 new temp, 41 42 /* path as spaces */ 43 " ", 44 ' ', 45 46 /* empty path */ 47 "", 48 '', 49 NULL, 50 null 51); 52 53function check_dirname( $paths ) { 54 $loop_counter = 0; 55 $noOfPaths = count($paths); 56 for( ; $loop_counter < $noOfPaths; $loop_counter++ ) { 57 echo "\n--Iteration "; 58 echo $loop_counter +1; 59 echo " --\n"; 60 var_dump( dirname($paths[$loop_counter]) ); 61 } 62} 63 64echo "*** Testing possible variations in path ***\n"; 65check_dirname( $file_path_variations ); 66 67echo "Done\n"; 68?> 69--EXPECTREGEX-- 70\*\*\* Testing possible variations in path \*\*\* 71 72--Iteration 1 -- 73string\(11\) "~(\\|\/)home(\\|\/)user" 74 75--Iteration 2 -- 76string\(11\) "~(\\|\/)home(\\|\/)user" 77 78--Iteration 3 -- 79string\(11\) "~(\\|\/)home(\\|\/)user" 80 81--Iteration 4 -- 82string\(11\) "~(\\|\/)home(\\|\/)user" 83 84--Iteration 5 -- 85string\(19\) "hostname:(\\|\/)home(\\|\/)user" 86 87--Iteration 6 -- 88string\(19\) "hostname:(\\|\/)home(\\|\/)user" 89 90--Iteration 7 -- 91string\(19\) "hostname:(\\|\/)home(\\|\/)user" 92 93--Iteration 8 -- 94string\(19\) "hostname:(\\|\/)home(\\|\/)user" 95 96--Iteration 9 -- 97string\(19\) "hostname:(\\|\/)home(\\|\/)user" 98 99--Iteration 10 -- 100string\(19\) "hostname:(\\|\/)home(\\|\/)user" 101 102--Iteration 11 -- 103string\(1\) "." 104 105--Iteration 12 -- 106string\(1\) "(\\|\/)" 107 108--Iteration 13 -- 109string\(1\) "(\\|\/)" 110 111--Iteration 14 -- 112string\(1\) "." 113 114--Iteration 15 -- 115string\(2\) "10" 116 117--Iteration 16 -- 118string\(1\) "." 119 120--Iteration 17 -- 121string\(1\) "." 122 123--Iteration 18 -- 124string\(1\) "." 125 126--Iteration 19 -- 127string\(1\) "." 128 129--Iteration 20 -- 130string\(1\) "." 131 132--Iteration 21 -- 133string\(0\) "" 134 135--Iteration 22 -- 136string\(0\) "" 137 138--Iteration 23 -- 139string\(0\) "" 140 141--Iteration 24 -- 142string\(0\) "" 143Done 144