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
<>);
31 // Initialise function arguments not being substituted
41 $index_array = varray
[1, 2, 3];
42 $assoc_array = darray
['one' => 1, 'two' => 2];
44 //array of values to iterate over
51 'int -12345' => -2345,
55 'float -10.5' => -10.5,
56 'float 12.3456789000e10' => 12.3456789000e10
,
57 'float -12.3456789000e10' => -12.3456789000e10
,
61 'empty array' => varray
[],
62 'int indexed array' => $index_array,
63 'associative array' => $assoc_array,
64 'nested arrays' => varray
['foo', $index_array, $assoc_array],
67 'uppercase NULL' => NULL,
68 'lowercase null' => null,
71 'lowercase true' => true,
72 'lowercase false' =>false,
73 'uppercase TRUE' =>TRUE,
74 'uppercase FALSE' =>FALSE,
77 'empty string DQ' => "",
78 'empty string SQ' => '',
81 'instance of classWithToString' => new classWithToString(),
82 'instance of classWithoutToString' => new classWithoutToString(),
87 // loop through each element of the array for suffix
89 foreach($inputs as $key =>$value) {
91 try { var_dump( basename($path, $value) ); } catch (Exception
$e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__
.' on line '.__LINE__
."\n"; }