2 /* Prototype : string basename(string path [, string suffix])
3 * Description: Returns the filename component of the path
4 * Source code: ext/standard/string.c
9 class classWithToString
11 public function __toString() {
12 return "Class A object";
16 class classWithoutToString
20 // Define error handler
21 function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
22 if (error_reporting() != 0) {
23 // report non-silenced errors
24 echo "Error: $err_no - $err_msg, $filename($linenum)\n";
27 <<__EntryPoint
>> function main(): void
{
28 echo "*** Testing basename() : usage variation ***\n";
29 set_error_handler(test_error_handler
<>);
38 $index_array = varray
[1, 2, 3];
39 $assoc_array = darray
['one' => 1, 'two' => 2];
41 //array of values to iterate over
48 'int -12345' => -2345,
52 'float -10.5' => -10.5,
53 'float 12.3456789000e10' => 12.3456789000e10
,
54 'float -12.3456789000e10' => -12.3456789000e10
,
58 'empty array' => varray
[],
59 'int indexed array' => $index_array,
60 'associative array' => $assoc_array,
61 'nested arrays' => varray
['foo', $index_array, $assoc_array],
64 'uppercase NULL' => NULL,
65 'lowercase null' => null,
68 'lowercase true' => true,
69 'lowercase false' =>false,
70 'uppercase TRUE' =>TRUE,
71 'uppercase FALSE' =>FALSE,
74 'empty string DQ' => "",
75 'empty string SQ' => '',
78 'instance of classWithToString' => new classWithToString(),
79 'instance of classWithoutToString' => new classWithoutToString(),
84 // loop through each element of the array for path
86 foreach($inputs as $key =>$value) {
88 try { var_dump( basename($value) ); } catch (Exception
$e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__
.' on line '.__LINE__
."\n"; }