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