1--TEST-- 2Test pathinfo() function : usage variation 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype : array pathinfo(string path[, int options]) 8 * Description: Returns information about a certain string 9 * Source code: ext/standard/string.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing pathinfo() : 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$options = PATHINFO_DIRNAME; 26 27//get an unset variable 28$unset_var = 10; 29unset ($unset_var); 30 31// define some classes 32class classWithToString 33{ 34 public function __toString() { 35 return "Class A object"; 36 } 37} 38 39class classWithoutToString 40{ 41} 42 43// heredoc string 44$heredoc = <<<EOT 45hello world 46EOT; 47 48// add arrays 49$index_array = array (1, 2, 3); 50$assoc_array = array ('one' => 1, 'two' => 2); 51 52//array of values to iterate over 53$inputs = array( 54 55 // int data 56 'int 0' => 0, 57 'int 1' => 1, 58 'int 12345' => 12345, 59 'int -12345' => -2345, 60 61 // float data 62 'float 10.5' => 10.5, 63 'float -10.5' => -10.5, 64 'float 12.3456789000e10' => 12.3456789000e10, 65 'float -12.3456789000e10' => -12.3456789000e10, 66 'float .5' => .5, 67 68 // array data 69 'empty array' => array(), 70 'int indexed array' => $index_array, 71 'associative array' => $assoc_array, 72 'nested arrays' => array('foo', $index_array, $assoc_array), 73 74 // null data 75 'uppercase NULL' => NULL, 76 'lowercase null' => null, 77 78 // boolean data 79 'lowercase true' => true, 80 'lowercase false' =>false, 81 'uppercase TRUE' =>TRUE, 82 'uppercase FALSE' =>FALSE, 83 84 // empty data 85 'empty string DQ' => "", 86 'empty string SQ' => '', 87 88 // object data 89 'instance of classWithToString' => new classWithToString(), 90 'instance of classWithoutToString' => new classWithoutToString(), 91 92 // undefined data 93 'undefined var' => @$undefined_var, 94 95 // unset data 96 'unset var' => @$unset_var, 97); 98 99// loop through each element of the array for path 100 101foreach($inputs as $key =>$value) { 102 echo "\n--$key--\n"; 103 var_dump( pathinfo($value, $options) ); 104}; 105 106?> 107===DONE=== 108--EXPECTF-- 109*** Testing pathinfo() : usage variation *** 110 111--int 0-- 112string(1) "." 113 114--int 1-- 115string(1) "." 116 117--int 12345-- 118string(1) "." 119 120--int -12345-- 121string(1) "." 122 123--float 10.5-- 124string(1) "." 125 126--float -10.5-- 127string(1) "." 128 129--float 12.3456789000e10-- 130string(1) "." 131 132--float -12.3456789000e10-- 133string(1) "." 134 135--float .5-- 136string(1) "." 137 138--empty array-- 139Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d) 140NULL 141 142--int indexed array-- 143Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d) 144NULL 145 146--associative array-- 147Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d) 148NULL 149 150--nested arrays-- 151Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d) 152NULL 153 154--uppercase NULL-- 155string(0) "" 156 157--lowercase null-- 158string(0) "" 159 160--lowercase true-- 161string(1) "." 162 163--lowercase false-- 164string(0) "" 165 166--uppercase TRUE-- 167string(1) "." 168 169--uppercase FALSE-- 170string(0) "" 171 172--empty string DQ-- 173string(0) "" 174 175--empty string SQ-- 176string(0) "" 177 178--instance of classWithToString-- 179string(1) "." 180 181--instance of classWithoutToString-- 182Error: 2 - pathinfo() expects parameter 1 to be string, object given, %s(%d) 183NULL 184 185--undefined var-- 186string(0) "" 187 188--unset var-- 189string(0) "" 190===DONE=== 191