mb_ereg_variation2.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. --TEST--
  2. Test mb_ereg() function : usage variations - pass different data types to $string arg
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_ereg(string $pattern, string $string [, array $registers])
  11. * Description: Regular expression match for multibyte string
  12. * Source code: ext/mbstring/php_mbregex.c
  13. */
  14. /*
  15. * Test behaviour of mb_ereg() when passed different data types as $string arg
  16. */
  17. echo "*** Testing mb_ereg() : usage variations ***\n";
  18. // Initialise function arguments not being substituted
  19. $pattern = 'str';
  20. //get an unset variable
  21. $unset_var = 10;
  22. unset ($unset_var);
  23. // get a class
  24. class classA
  25. {
  26. public function __toString() {
  27. return "Class A object";
  28. }
  29. }
  30. // heredoc string
  31. $heredoc = <<<EOT
  32. hello world
  33. EOT;
  34. // get a resource variable
  35. $fp = fopen(__FILE__, "r");
  36. // unexpected values to be passed to $string 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. // empty data
  58. /*16*/ "",
  59. '',
  60. // string data
  61. /*18*/ "string",
  62. 'string',
  63. $heredoc,
  64. // object data
  65. /*21*/ new classA(),
  66. // undefined data
  67. /*22*/ @$undefined_var,
  68. // unset data
  69. /*23*/ @$unset_var,
  70. // resource variable
  71. /*24*/ $fp
  72. );
  73. // loop through each element of $inputs to check the behavior of mb_ereg()
  74. $iterator = 1;
  75. foreach($inputs as $input) {
  76. if (@is_array($regs)){
  77. $regs = null;
  78. }
  79. echo "\n-- Iteration $iterator --\n";
  80. var_dump( mb_ereg($pattern, $input, $regs) );
  81. var_dump($regs);
  82. $iterator++;
  83. };
  84. fclose($fp);
  85. echo "Done";
  86. ?>
  87. --EXPECTF--
  88. *** Testing mb_ereg() : usage variations ***
  89. -- Iteration 1 --
  90. bool(false)
  91. NULL
  92. -- Iteration 2 --
  93. bool(false)
  94. NULL
  95. -- Iteration 3 --
  96. bool(false)
  97. NULL
  98. -- Iteration 4 --
  99. bool(false)
  100. NULL
  101. -- Iteration 5 --
  102. bool(false)
  103. NULL
  104. -- Iteration 6 --
  105. bool(false)
  106. NULL
  107. -- Iteration 7 --
  108. bool(false)
  109. NULL
  110. -- Iteration 8 --
  111. bool(false)
  112. NULL
  113. -- Iteration 9 --
  114. bool(false)
  115. NULL
  116. -- Iteration 10 --
  117. bool(false)
  118. NULL
  119. -- Iteration 11 --
  120. bool(false)
  121. NULL
  122. -- Iteration 12 --
  123. bool(false)
  124. NULL
  125. -- Iteration 13 --
  126. bool(false)
  127. NULL
  128. -- Iteration 14 --
  129. bool(false)
  130. NULL
  131. -- Iteration 15 --
  132. bool(false)
  133. NULL
  134. -- Iteration 16 --
  135. bool(false)
  136. NULL
  137. -- Iteration 17 --
  138. bool(false)
  139. NULL
  140. -- Iteration 18 --
  141. int(3)
  142. array(1) {
  143. [0]=>
  144. string(3) "str"
  145. }
  146. -- Iteration 19 --
  147. int(3)
  148. array(1) {
  149. [0]=>
  150. string(3) "str"
  151. }
  152. -- Iteration 20 --
  153. bool(false)
  154. NULL
  155. -- Iteration 21 --
  156. bool(false)
  157. NULL
  158. -- Iteration 22 --
  159. bool(false)
  160. NULL
  161. -- Iteration 23 --
  162. bool(false)
  163. NULL
  164. -- Iteration 24 --
  165. Warning: mb_ereg() expects parameter 2 to be string, resource given in %s on line %d
  166. bool(false)
  167. NULL
  168. Done