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$path = '/usr/include/arpa/inet.h';
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      // float data
56      'float 10.5' => 10.5,
57      'float -10.5' => -10.5,
58      'float 12.3456789000e10' => 12.3456789000e10,
59      'float -12.3456789000e10' => -12.3456789000e10,
60      'float .5' => .5,
61
62      // array data
63      'empty array' => array(),
64      'int indexed array' => $index_array,
65      'associative array' => $assoc_array,
66      'nested arrays' => array('foo', $index_array, $assoc_array),
67
68      // null data
69      'uppercase NULL' => NULL,
70      'lowercase null' => null,
71
72      // boolean data
73      'lowercase true' => true,
74      'lowercase false' =>false,
75      'uppercase TRUE' =>TRUE,
76      'uppercase FALSE' =>FALSE,
77
78      // empty data
79      'empty string DQ' => "",
80      'empty string SQ' => '',
81
82      // string data
83      'string DQ' => "string",
84      'string SQ' => 'string',
85      'mixed case string' => "sTrInG",
86      'heredoc' => $heredoc,
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 options
100
101foreach($inputs as $key =>$value) {
102      echo "\n--$key--\n";
103      var_dump( pathinfo($path, $value) );
104};
105
106?>
107===DONE===
108--EXPECTF--
109*** Testing pathinfo() : usage variation ***
110
111--float 10.5--
112string(6) "inet.h"
113
114--float -10.5--
115string(6) "inet.h"
116
117--float 12.3456789000e10--
118string(%d) %s
119
120--float -12.3456789000e10--
121string(%d) %s
122
123--float .5--
124string(%d) %s
125
126--empty array--
127Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d)
128NULL
129
130--int indexed array--
131Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d)
132NULL
133
134--associative array--
135Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d)
136NULL
137
138--nested arrays--
139Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d)
140NULL
141
142--uppercase NULL--
143string(0) ""
144
145--lowercase null--
146string(0) ""
147
148--lowercase true--
149string(17) "/usr/include/arpa"
150
151--lowercase false--
152string(0) ""
153
154--uppercase TRUE--
155string(17) "/usr/include/arpa"
156
157--uppercase FALSE--
158string(0) ""
159
160--empty string DQ--
161Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
162NULL
163
164--empty string SQ--
165Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
166NULL
167
168--string DQ--
169Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
170NULL
171
172--string SQ--
173Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
174NULL
175
176--mixed case string--
177Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
178NULL
179
180--heredoc--
181Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d)
182NULL
183
184--instance of classWithToString--
185Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d)
186NULL
187
188--instance of classWithoutToString--
189Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d)
190NULL
191
192--undefined var--
193string(0) ""
194
195--unset var--
196string(0) ""
197===DONE===
198