mb_stristr_variation1.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. --TEST--
  2. Test mb_stristr() function : usage variation - various haystacks, needle won't be found
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_stristr') or die("skip mb_stristr() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_stristr(string haystack, string needle[, bool part[, string encoding]])
  11. * Description: Finds first occurrence of a string within another, case insensitive
  12. * Source code: ext/mbstring/mbstring.c
  13. * Alias to functions:
  14. */
  15. echo "*** Testing mb_stristr() : usage variation ***\n";
  16. // Define error handler
  17. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  18. if (error_reporting() != 0) {
  19. // report non-silenced errors
  20. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  21. }
  22. }
  23. set_error_handler('test_error_handler');
  24. // Initialise function arguments not being substituted (if any)
  25. $needle = b'string_val';
  26. $part = true;
  27. $encoding = 'utf-8';
  28. //get an unset variable
  29. $unset_var = 10;
  30. unset ($unset_var);
  31. // define some classes
  32. class classWithToString
  33. {
  34. public function __toString() {
  35. return b"Class A object";
  36. }
  37. }
  38. class classWithoutToString
  39. {
  40. }
  41. // heredoc string
  42. $heredoc = b<<<EOT
  43. hello world
  44. EOT;
  45. // get a resource variable
  46. $fp = fopen(__FILE__, "r");
  47. // add arrays
  48. $index_array = array (1, 2, 3);
  49. $assoc_array = array ('one' => 1, 'two' => 2);
  50. //array of values to iterate over
  51. $inputs = array(
  52. // int data
  53. 'int 0' => 0,
  54. 'int 1' => 1,
  55. 'int 12345' => 12345,
  56. 'int -12345' => -2345,
  57. // float data
  58. 'float 10.5' => 10.5,
  59. 'float -10.5' => -10.5,
  60. 'float 12.3456789000e10' => 12.3456789000e10,
  61. 'float -12.3456789000e10' => -12.3456789000e10,
  62. 'float .5' => .5,
  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. // null data
  69. 'uppercase NULL' => NULL,
  70. 'lowercase null' => null,
  71. // boolean data
  72. 'lowercase true' => true,
  73. 'lowercase false' =>false,
  74. 'uppercase TRUE' =>TRUE,
  75. 'uppercase FALSE' =>FALSE,
  76. // empty data
  77. 'empty string DQ' => "",
  78. 'empty string SQ' => '',
  79. // object data
  80. 'instance of classWithToString' => new classWithToString(),
  81. 'instance of classWithoutToString' => new classWithoutToString(),
  82. // undefined data
  83. 'undefined var' => @$undefined_var,
  84. // unset data
  85. 'unset var' => @$unset_var,
  86. // resource variable
  87. 'resource' => $fp
  88. );
  89. // loop through each element of the array for haystack
  90. foreach($inputs as $key =>$value) {
  91. echo "\n--$key--\n";
  92. var_dump( mb_stristr($value, $needle, $part, $encoding) );
  93. };
  94. fclose($fp);
  95. ?>
  96. ===DONE===
  97. --EXPECTF--
  98. *** Testing mb_stristr() : usage variation ***
  99. --int 0--
  100. bool(false)
  101. --int 1--
  102. bool(false)
  103. --int 12345--
  104. bool(false)
  105. --int -12345--
  106. bool(false)
  107. --float 10.5--
  108. bool(false)
  109. --float -10.5--
  110. bool(false)
  111. --float 12.3456789000e10--
  112. bool(false)
  113. --float -12.3456789000e10--
  114. bool(false)
  115. --float .5--
  116. bool(false)
  117. --empty array--
  118. Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
  119. bool(false)
  120. --int indexed array--
  121. Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
  122. bool(false)
  123. --associative array--
  124. Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
  125. bool(false)
  126. --nested arrays--
  127. Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
  128. bool(false)
  129. --uppercase NULL--
  130. bool(false)
  131. --lowercase null--
  132. bool(false)
  133. --lowercase true--
  134. bool(false)
  135. --lowercase false--
  136. bool(false)
  137. --uppercase TRUE--
  138. bool(false)
  139. --uppercase FALSE--
  140. bool(false)
  141. --empty string DQ--
  142. bool(false)
  143. --empty string SQ--
  144. bool(false)
  145. --instance of classWithToString--
  146. bool(false)
  147. --instance of classWithoutToString--
  148. Error: 2 - mb_stristr() expects parameter 1 to be string, object given, %s(%d)
  149. bool(false)
  150. --undefined var--
  151. bool(false)
  152. --unset var--
  153. bool(false)
  154. --resource--
  155. Error: 2 - mb_stristr() expects parameter 1 to be string, resource given, %s(%d)
  156. bool(false)
  157. ===DONE===