mb_ereg_variation1.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. --TEST--
  2. Test mb_ereg() function : usage variations - pass different data types to $pattern argument
  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. * Pass different data types to $pattern argument
  16. */
  17. echo "*** Testing mb_ereg() : usage variations ***\n";
  18. // Initialise function arguments not being substituted (if any)
  19. $string = 'string value';
  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 $pattern 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. // boolean data
  50. /*10*/ true,
  51. TRUE,
  52. // string data
  53. /*12*/ "string",
  54. 'string',
  55. $heredoc,
  56. // object data
  57. /*15*/ new classA(),
  58. // resource variable
  59. /*16*/ $fp
  60. );
  61. // loop through each element of $inputs to check the behavior of mb_ereg()
  62. $iterator = 1;
  63. foreach($inputs as $input) {
  64. if (@is_array($regs)){
  65. $regs = null;
  66. }
  67. echo "\n-- Iteration $iterator --\n";
  68. var_dump( mb_ereg($input, $string, $regs) );
  69. var_dump($regs);
  70. $iterator++;
  71. };
  72. fclose($fp);
  73. echo "Done";
  74. ?>
  75. --EXPECTF--
  76. *** Testing mb_ereg() : usage variations ***
  77. -- Iteration 1 --
  78. bool(false)
  79. NULL
  80. -- Iteration 2 --
  81. bool(false)
  82. NULL
  83. -- Iteration 3 --
  84. bool(false)
  85. NULL
  86. -- Iteration 4 --
  87. bool(false)
  88. NULL
  89. -- Iteration 5 --
  90. bool(false)
  91. NULL
  92. -- Iteration 6 --
  93. bool(false)
  94. NULL
  95. -- Iteration 7 --
  96. bool(false)
  97. NULL
  98. -- Iteration 8 --
  99. bool(false)
  100. NULL
  101. -- Iteration 9 --
  102. bool(false)
  103. NULL
  104. -- Iteration 10 --
  105. bool(false)
  106. NULL
  107. -- Iteration 11 --
  108. bool(false)
  109. NULL
  110. -- Iteration 12 --
  111. int(6)
  112. array(1) {
  113. [0]=>
  114. string(6) "string"
  115. }
  116. -- Iteration 13 --
  117. int(6)
  118. array(1) {
  119. [0]=>
  120. string(6) "string"
  121. }
  122. -- Iteration 14 --
  123. bool(false)
  124. NULL
  125. -- Iteration 15 --
  126. bool(false)
  127. NULL
  128. -- Iteration 16 --
  129. bool(false)
  130. NULL
  131. Done