mb_stripos_variation4.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. --TEST--
  2. Test mb_stripos() function : usage variations - pass different data types as $encoding arg
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
  11. * Description: Finds position of first occurrence of a string within another, case insensitive
  12. * Source code: ext/mbstring/mbstring.c
  13. * Alias to functions:
  14. */
  15. /*
  16. * Pass mb_stripos different data types as $encoding arg to test behaviour
  17. * Where possible 'UTF-8' has been entered as a string value
  18. */
  19. echo "*** Testing mb_stripos() : usage variations ***\n";
  20. // Initialise function arguments not being substituted
  21. $haystack = b'string_val';
  22. $needle = b'VaL';
  23. $offset = 0;
  24. //get an unset variable
  25. $unset_var = 10;
  26. unset ($unset_var);
  27. // get a class
  28. class classA
  29. {
  30. public function __toString() {
  31. return "UTF-8";
  32. }
  33. }
  34. // heredoc string
  35. $heredoc = <<<EOT
  36. UTF-8
  37. EOT;
  38. // get a resource variable
  39. $fp = fopen(__FILE__, "r");
  40. // unexpected values to be passed to $input argument
  41. $inputs = array(
  42. // int data
  43. /*1*/ 0,
  44. 1,
  45. 12345,
  46. -2345,
  47. // float data
  48. /*5*/ 10.5,
  49. -10.5,
  50. 12.3456789000e10,
  51. 12.3456789000E-10,
  52. .5,
  53. // null data
  54. /*10*/ NULL,
  55. null,
  56. // boolean data
  57. /*12*/ true,
  58. false,
  59. TRUE,
  60. FALSE,
  61. // empty data
  62. /*16*/ "",
  63. '',
  64. // string data
  65. /*18*/ "UTF-8",
  66. 'UTF-8',
  67. $heredoc,
  68. // object data
  69. /*21*/ new classA(),
  70. // undefined data
  71. /*22*/ @$undefined_var,
  72. // unset data
  73. /*23*/ @$unset_var,
  74. // resource variable
  75. /*24*/ $fp
  76. );
  77. // loop through each element of $inputs to check the behavior of mb_stripos()
  78. $iterator = 1;
  79. foreach($inputs as $input) {
  80. echo "\n-- Iteration $iterator --\n";
  81. var_dump( mb_stripos($haystack, $needle, $offset, $input));
  82. $iterator++;
  83. };
  84. fclose($fp);
  85. echo "Done";
  86. ?>
  87. --EXPECTF--
  88. *** Testing mb_stripos() : usage variations ***
  89. -- Iteration 1 --
  90. Warning: mb_stripos(): Unknown encoding "0" in %s on line %d
  91. bool(false)
  92. -- Iteration 2 --
  93. Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
  94. bool(false)
  95. -- Iteration 3 --
  96. Warning: mb_stripos(): Unknown encoding "12345" in %s on line %d
  97. bool(false)
  98. -- Iteration 4 --
  99. Warning: mb_stripos(): Unknown encoding "-2345" in %s on line %d
  100. bool(false)
  101. -- Iteration 5 --
  102. Warning: mb_stripos(): Unknown encoding "10.5" in %s on line %d
  103. bool(false)
  104. -- Iteration 6 --
  105. Warning: mb_stripos(): Unknown encoding "-10.5" in %s on line %d
  106. bool(false)
  107. -- Iteration 7 --
  108. Warning: mb_stripos(): Unknown encoding "123456789000" in %s on line %d
  109. bool(false)
  110. -- Iteration 8 --
  111. Warning: mb_stripos(): Unknown encoding "1.23456789E-9" in %s on line %d
  112. bool(false)
  113. -- Iteration 9 --
  114. Warning: mb_stripos(): Unknown encoding "0.5" in %s on line %d
  115. bool(false)
  116. -- Iteration 10 --
  117. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  118. bool(false)
  119. -- Iteration 11 --
  120. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  121. bool(false)
  122. -- Iteration 12 --
  123. Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
  124. bool(false)
  125. -- Iteration 13 --
  126. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  127. bool(false)
  128. -- Iteration 14 --
  129. Warning: mb_stripos(): Unknown encoding "1" in %s on line %d
  130. bool(false)
  131. -- Iteration 15 --
  132. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  133. bool(false)
  134. -- Iteration 16 --
  135. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  136. bool(false)
  137. -- Iteration 17 --
  138. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  139. bool(false)
  140. -- Iteration 18 --
  141. int(7)
  142. -- Iteration 19 --
  143. int(7)
  144. -- Iteration 20 --
  145. int(7)
  146. -- Iteration 21 --
  147. int(7)
  148. -- Iteration 22 --
  149. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  150. bool(false)
  151. -- Iteration 23 --
  152. Warning: mb_stripos(): Unknown encoding "" in %s on line %d
  153. bool(false)
  154. -- Iteration 24 --
  155. Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d
  156. bool(false)
  157. Done