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