mb_stripos_variation1.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. --TEST--
  2. Test mb_stripos() function : usage variations - pass different data types to $haystack 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 $haystack arg to test behaviour
  17. */
  18. echo "*** Testing mb_stripos() : usage variations ***\n";
  19. // Initialise function arguments not being substituted
  20. $needle = b'string_val';
  21. $offset = 0;
  22. $encoding = 'utf-8';
  23. //get an unset variable
  24. $unset_var = 10;
  25. unset ($unset_var);
  26. // get a class
  27. class classA
  28. {
  29. public function __toString() {
  30. return "Class A object";
  31. }
  32. }
  33. // heredoc string
  34. $heredoc = <<<EOT
  35. hello world
  36. EOT;
  37. // get a resource variable
  38. $fp = fopen(__FILE__, "r");
  39. // unexpected values to be passed to $haystack argument
  40. $inputs = array(
  41. // int data
  42. /*1*/ 0,
  43. 1,
  44. 12345,
  45. -2345,
  46. // float data
  47. /*5*/ 10.5,
  48. -10.5,
  49. 12.3456789000e10,
  50. 12.3456789000E-10,
  51. .5,
  52. // null data
  53. /*10*/ NULL,
  54. null,
  55. // boolean data
  56. /*12*/ true,
  57. false,
  58. TRUE,
  59. FALSE,
  60. // empty data
  61. /*16*/ "",
  62. '',
  63. // string data
  64. /*18*/ "string",
  65. 'string',
  66. $heredoc,
  67. // object data
  68. /*21*/ new classA(),
  69. // undefined data
  70. /*22*/ @$undefined_var,
  71. // unset data
  72. /*23*/ @$unset_var,
  73. // resource variable
  74. /*24*/ $fp
  75. );
  76. // loop through each element of $inputs to check the behavior of mb_stripos()
  77. $iterator = 1;
  78. foreach($inputs as $input) {
  79. echo "\n-- Iteration $iterator --\n";
  80. var_dump( mb_stripos($input, $needle, $offset, $encoding));
  81. $iterator++;
  82. };
  83. fclose($fp);
  84. echo "Done";
  85. ?>
  86. --EXPECTF--
  87. *** Testing mb_stripos() : usage variations ***
  88. -- Iteration 1 --
  89. bool(false)
  90. -- Iteration 2 --
  91. bool(false)
  92. -- Iteration 3 --
  93. bool(false)
  94. -- Iteration 4 --
  95. bool(false)
  96. -- Iteration 5 --
  97. bool(false)
  98. -- Iteration 6 --
  99. bool(false)
  100. -- Iteration 7 --
  101. bool(false)
  102. -- Iteration 8 --
  103. bool(false)
  104. -- Iteration 9 --
  105. bool(false)
  106. -- Iteration 10 --
  107. bool(false)
  108. -- Iteration 11 --
  109. bool(false)
  110. -- Iteration 12 --
  111. bool(false)
  112. -- Iteration 13 --
  113. bool(false)
  114. -- Iteration 14 --
  115. bool(false)
  116. -- Iteration 15 --
  117. bool(false)
  118. -- Iteration 16 --
  119. bool(false)
  120. -- Iteration 17 --
  121. bool(false)
  122. -- Iteration 18 --
  123. bool(false)
  124. -- Iteration 19 --
  125. bool(false)
  126. -- Iteration 20 --
  127. bool(false)
  128. -- Iteration 21 --
  129. bool(false)
  130. -- Iteration 22 --
  131. bool(false)
  132. -- Iteration 23 --
  133. bool(false)
  134. -- Iteration 24 --
  135. Warning: mb_stripos() expects parameter 1 to be string, resource given in %s on line %d
  136. bool(false)
  137. Done