mb_regex_encoding_variation1.phpt 4.1 KB

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