basename_variation4.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. --TEST--
  2. Test 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. echo "*** Testing basename() : usage variation ***\n";
  11. // Define error handler
  12. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  13. if (error_reporting() != 0) {
  14. // report non-silenced errors
  15. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  16. }
  17. }
  18. set_error_handler('test_error_handler');
  19. // Initialise function arguments not being substituted
  20. $path = 'path';
  21. //get an unset variable
  22. $unset_var = 10;
  23. unset ($unset_var);
  24. // define some classes
  25. class classWithToString
  26. {
  27. public function __toString() {
  28. return "Class A object";
  29. }
  30. }
  31. class classWithoutToString
  32. {
  33. }
  34. // heredoc string
  35. $heredoc = <<<EOT
  36. hello world
  37. EOT;
  38. // add arrays
  39. $index_array = array (1, 2, 3);
  40. $assoc_array = array ('one' => 1, 'two' => 2);
  41. //array of values to iterate over
  42. $inputs = array(
  43. // int data
  44. 'int 0' => 0,
  45. 'int 1' => 1,
  46. 'int 12345' => 12345,
  47. 'int -12345' => -2345,
  48. // float data
  49. 'float 10.5' => 10.5,
  50. 'float -10.5' => -10.5,
  51. 'float 12.3456789000e10' => 12.3456789000e10,
  52. 'float -12.3456789000e10' => -12.3456789000e10,
  53. 'float .5' => .5,
  54. // array data
  55. 'empty array' => array(),
  56. 'int indexed array' => $index_array,
  57. 'associative array' => $assoc_array,
  58. 'nested arrays' => array('foo', $index_array, $assoc_array),
  59. // null data
  60. 'uppercase NULL' => NULL,
  61. 'lowercase null' => null,
  62. // boolean data
  63. 'lowercase true' => true,
  64. 'lowercase false' =>false,
  65. 'uppercase TRUE' =>TRUE,
  66. 'uppercase FALSE' =>FALSE,
  67. // empty data
  68. 'empty string DQ' => "",
  69. 'empty string SQ' => '',
  70. // object data
  71. 'instance of classWithToString' => new classWithToString(),
  72. 'instance of classWithoutToString' => new classWithoutToString(),
  73. // undefined data
  74. 'undefined var' => @$undefined_var,
  75. // unset data
  76. 'unset var' => @$unset_var,
  77. );
  78. // loop through each element of the array for suffix
  79. foreach($inputs as $key =>$value) {
  80. echo "\n--$key--\n";
  81. var_dump( basename($path, $value) );
  82. };
  83. ?>
  84. ===DONE===
  85. --EXPECTF--
  86. *** Testing basename() : usage variation ***
  87. --int 0--
  88. string(4) "path"
  89. --int 1--
  90. string(4) "path"
  91. --int 12345--
  92. string(4) "path"
  93. --int -12345--
  94. string(4) "path"
  95. --float 10.5--
  96. string(4) "path"
  97. --float -10.5--
  98. string(4) "path"
  99. --float 12.3456789000e10--
  100. string(4) "path"
  101. --float -12.3456789000e10--
  102. string(4) "path"
  103. --float .5--
  104. string(4) "path"
  105. --empty array--
  106. Error: 2 - basename() expects parameter 2 to be string, array given, %s(%d)
  107. NULL
  108. --int indexed array--
  109. Error: 2 - basename() expects parameter 2 to be string, array given, %s(%d)
  110. NULL
  111. --associative array--
  112. Error: 2 - basename() expects parameter 2 to be string, array given, %s(%d)
  113. NULL
  114. --nested arrays--
  115. Error: 2 - basename() expects parameter 2 to be string, array given, %s(%d)
  116. NULL
  117. --uppercase NULL--
  118. string(4) "path"
  119. --lowercase null--
  120. string(4) "path"
  121. --lowercase true--
  122. string(4) "path"
  123. --lowercase false--
  124. string(4) "path"
  125. --uppercase TRUE--
  126. string(4) "path"
  127. --uppercase FALSE--
  128. string(4) "path"
  129. --empty string DQ--
  130. string(4) "path"
  131. --empty string SQ--
  132. string(4) "path"
  133. --instance of classWithToString--
  134. string(4) "path"
  135. --instance of classWithoutToString--
  136. Error: 2 - basename() expects parameter 2 to be string, object given, %s(%d)
  137. NULL
  138. --undefined var--
  139. string(4) "path"
  140. --unset var--
  141. string(4) "path"
  142. ===DONE===