mb_strrpos_variation3.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --TEST--
  2. Test mb_strrpos() function : usage variations - Pass different data types as $offset arg
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
  11. * Description: Find position of last occurrence of a string within another
  12. * Source code: ext/mbstring/mbstring.c
  13. */
  14. /*
  15. * Pass mb_strrpos() different data types as $offset argument to test behaviour
  16. */
  17. echo "*** Testing mb_strrpos() : usage variations ***\n";
  18. // Initialise function arguments not being substituted
  19. $needle = b'a';
  20. $haystack = b'string_val';
  21. $encoding = 'utf-8';
  22. //get an unset variable
  23. $unset_var = 10;
  24. unset ($unset_var);
  25. // get a class
  26. class classA
  27. {
  28. public function __toString() {
  29. return b"7";
  30. }
  31. }
  32. // heredoc string
  33. $heredoc = b<<<EOT
  34. hello world
  35. EOT;
  36. // unexpected values to be passed to $offset argument
  37. $inputs = array(
  38. // int data
  39. /*1*/ 0,
  40. 1,
  41. 12345,
  42. -2345,
  43. // float data
  44. /*5*/ 10.5,
  45. -10.5,
  46. 12.3456789000e10,
  47. 12.3456789000E-10,
  48. .5,
  49. // null data
  50. /*10*/ NULL,
  51. null,
  52. // boolean data
  53. /*12*/ true,
  54. false,
  55. TRUE,
  56. FALSE,
  57. // object data
  58. /*16*/ new classA(),
  59. // undefined data
  60. /*17*/ @$undefined_var,
  61. // unset data
  62. /*18*/ @$unset_var
  63. );
  64. // loop through each element of $inputs to check the behavior of mb_strrpos()
  65. $iterator = 1;
  66. foreach($inputs as $input) {
  67. echo "\n-- Iteration $iterator --\n";
  68. var_dump( mb_strrpos($haystack, $needle, $input, $encoding));
  69. $iterator++;
  70. };
  71. echo "Done";
  72. ?>
  73. --EXPECTF--
  74. *** Testing mb_strrpos() : usage variations ***
  75. -- Iteration 1 --
  76. int(8)
  77. -- Iteration 2 --
  78. int(8)
  79. -- Iteration 3 --
  80. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  81. bool(false)
  82. -- Iteration 4 --
  83. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  84. bool(false)
  85. -- Iteration 5 --
  86. bool(false)
  87. -- Iteration 6 --
  88. bool(false)
  89. -- Iteration 7 --
  90. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  91. bool(false)
  92. -- Iteration 8 --
  93. int(8)
  94. -- Iteration 9 --
  95. int(8)
  96. -- Iteration 10 --
  97. int(8)
  98. -- Iteration 11 --
  99. int(8)
  100. -- Iteration 12 --
  101. int(8)
  102. -- Iteration 13 --
  103. int(8)
  104. -- Iteration 14 --
  105. int(8)
  106. -- Iteration 15 --
  107. int(8)
  108. -- Iteration 16 --
  109. Notice: Object of class classA could not be converted to int in %s on line %d
  110. int(8)
  111. -- Iteration 17 --
  112. int(8)
  113. -- Iteration 18 --
  114. int(8)
  115. Done