2
Test pathinfo() function : usage variation
4
Dave Kelsey <d_kelsey@uk.ibm.com>
7
/* Prototype : array pathinfo(string path[, int options])
8
* Description: Returns information about a certain string
9
* Source code: ext/standard/string.c
13
echo "*** Testing pathinfo() : usage variation ***\n";
15
// Define error handler
16
function 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";
22
set_error_handler('test_error_handler');
24
// Initialise function arguments not being substituted (if any)
25
$options = PATHINFO_DIRNAME;
27
//get an unset variable
31
// define some classes
32
class classWithToString
34
public function __toString() {
35
return "Class A object";
39
class classWithoutToString
49
$index_array = array (1, 2, 3);
50
$assoc_array = array ('one' => 1, 'two' => 2);
52
//array of values to iterate over
59
'int -12345' => -2345,
63
'float -10.5' => -10.5,
64
'float 12.3456789000e10' => 12.3456789000e10,
65
'float -12.3456789000e10' => -12.3456789000e10,
69
'empty array' => array(),
70
'int indexed array' => $index_array,
71
'associative array' => $assoc_array,
72
'nested arrays' => array('foo', $index_array, $assoc_array),
75
'uppercase NULL' => NULL,
76
'lowercase null' => null,
79
'lowercase true' => true,
80
'lowercase false' =>false,
81
'uppercase TRUE' =>TRUE,
82
'uppercase FALSE' =>FALSE,
85
'empty string DQ' => "",
86
'empty string SQ' => '',
89
'instance of classWithToString' => new classWithToString(),
90
'instance of classWithoutToString' => new classWithoutToString(),
93
'undefined var' => @$undefined_var,
96
'unset var' => @$unset_var,
99
// loop through each element of the array for path
101
foreach($inputs as $key =>$value) {
103
var_dump( pathinfo($value, $options) );
109
*** Testing pathinfo() : usage variation ***
129
--float 12.3456789000e10--
132
--float -12.3456789000e10--
139
Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
142
--int indexed array--
143
Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
146
--associative array--
147
Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
151
Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
178
--instance of classWithToString--
181
--instance of classWithoutToString--
182
Error: 2 - pathinfo() expects parameter 1 to be string, object given, %s(%d)