split_variation_003.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. --TEST--
  2. Test split() function : usage variations - unexpected type for arg 3
  3. --FILE--
  4. <?php
  5. /* Prototype : proto array split(string pattern, string string [, int limit])
  6. * Description: Split string into array by regular expression
  7. * Source code: ext/standard/reg.c
  8. * Alias to functions:
  9. */
  10. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  11. if (error_reporting() != 0) {
  12. // report non-silenced errors
  13. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  14. }
  15. }
  16. set_error_handler('test_error_handler');
  17. echo "*** Testing split() : usage variations ***\n";
  18. // Initialise function arguments not being substituted (if any)
  19. $pattern = b'[[:space:]]';
  20. $string = '1 2 3 4 5';
  21. //get an unset variable
  22. $unset_var = 10;
  23. unset ($unset_var);
  24. //array of values to iterate over
  25. $values = array(
  26. // float data
  27. 10.5,
  28. -10.5,
  29. 10.7654321E-10,
  30. .5,
  31. // array data
  32. array(),
  33. array(0),
  34. array(1),
  35. array(1, 2),
  36. array('color' => 'red', 'item' => 'pen'),
  37. // null data
  38. NULL,
  39. null,
  40. // boolean data
  41. true,
  42. false,
  43. TRUE,
  44. FALSE,
  45. // empty data
  46. "",
  47. '',
  48. // string data
  49. "string",
  50. 'string',
  51. // object data
  52. new stdclass(),
  53. // undefined data
  54. @$undefined_var,
  55. // unset data
  56. @$unset_var,
  57. );
  58. // loop through each element of the array for limit
  59. foreach($values as $value) {
  60. echo "\nArg value $value \n";
  61. var_dump( split($pattern, $string, $value) );
  62. };
  63. echo "Done";
  64. ?>
  65. --EXPECTF--
  66. *** Testing split() : usage variations ***
  67. Arg value 10.5
  68. Error: 8192 - Function split() is deprecated, %s(73)
  69. array(5) {
  70. [0]=>
  71. string(1) "1"
  72. [1]=>
  73. string(1) "2"
  74. [2]=>
  75. string(1) "3"
  76. [3]=>
  77. string(1) "4"
  78. [4]=>
  79. string(1) "5"
  80. }
  81. Arg value -10.5
  82. Error: 8192 - Function split() is deprecated, %s(73)
  83. array(1) {
  84. [0]=>
  85. string(9) "1 2 3 4 5"
  86. }
  87. Arg value 1.07654321E-9
  88. Error: 8192 - Function split() is deprecated, %s(73)
  89. array(1) {
  90. [0]=>
  91. string(9) "1 2 3 4 5"
  92. }
  93. Arg value 0.5
  94. Error: 8192 - Function split() is deprecated, %s(73)
  95. array(1) {
  96. [0]=>
  97. string(9) "1 2 3 4 5"
  98. }
  99. Error: 8 - Array to string conversion, %ssplit_variation_003.php(%d)
  100. Arg value Array
  101. Error: 8192 - Function split() is deprecated, %s(73)
  102. Error: 2 - split() expects parameter 3 to be long, array given, %s(73)
  103. NULL
  104. Error: 8 - Array to string conversion, %ssplit_variation_003.php(%d)
  105. Arg value Array
  106. Error: 8192 - Function split() is deprecated, %s(73)
  107. Error: 2 - split() expects parameter 3 to be long, array given, %s(73)
  108. NULL
  109. Error: 8 - Array to string conversion, %ssplit_variation_003.php(%d)
  110. Arg value Array
  111. Error: 8192 - Function split() is deprecated, %s(73)
  112. Error: 2 - split() expects parameter 3 to be long, array given, %s(73)
  113. NULL
  114. Error: 8 - Array to string conversion, %ssplit_variation_003.php(%d)
  115. Arg value Array
  116. Error: 8192 - Function split() is deprecated, %s(73)
  117. Error: 2 - split() expects parameter 3 to be long, array given, %s(73)
  118. NULL
  119. Error: 8 - Array to string conversion, %ssplit_variation_003.php(%d)
  120. Arg value Array
  121. Error: 8192 - Function split() is deprecated, %s(73)
  122. Error: 2 - split() expects parameter 3 to be long, array given, %s(73)
  123. NULL
  124. Arg value
  125. Error: 8192 - Function split() is deprecated, %s(73)
  126. array(1) {
  127. [0]=>
  128. string(9) "1 2 3 4 5"
  129. }
  130. Arg value
  131. Error: 8192 - Function split() is deprecated, %s(73)
  132. array(1) {
  133. [0]=>
  134. string(9) "1 2 3 4 5"
  135. }
  136. Arg value 1
  137. Error: 8192 - Function split() is deprecated, %s(73)
  138. array(1) {
  139. [0]=>
  140. string(9) "1 2 3 4 5"
  141. }
  142. Arg value
  143. Error: 8192 - Function split() is deprecated, %s(73)
  144. array(1) {
  145. [0]=>
  146. string(9) "1 2 3 4 5"
  147. }
  148. Arg value 1
  149. Error: 8192 - Function split() is deprecated, %s(73)
  150. array(1) {
  151. [0]=>
  152. string(9) "1 2 3 4 5"
  153. }
  154. Arg value
  155. Error: 8192 - Function split() is deprecated, %s(73)
  156. array(1) {
  157. [0]=>
  158. string(9) "1 2 3 4 5"
  159. }
  160. Arg value
  161. Error: 8192 - Function split() is deprecated, %s(73)
  162. Error: 2 - split() expects parameter 3 to be long, string given, %s(73)
  163. NULL
  164. Arg value
  165. Error: 8192 - Function split() is deprecated, %s(73)
  166. Error: 2 - split() expects parameter 3 to be long, string given, %s(73)
  167. NULL
  168. Arg value string
  169. Error: 8192 - Function split() is deprecated, %s(73)
  170. Error: 2 - split() expects parameter 3 to be long, string given, %s(73)
  171. NULL
  172. Arg value string
  173. Error: 8192 - Function split() is deprecated, %s(73)
  174. Error: 2 - split() expects parameter 3 to be long, string given, %s(73)
  175. NULL
  176. Error: 4096 - Object of class stdClass could not be converted to string, %s(72)
  177. Arg value
  178. Error: 8192 - Function split() is deprecated, %s(73)
  179. Error: 2 - split() expects parameter 3 to be long, object given, %s(73)
  180. NULL
  181. Arg value
  182. Error: 8192 - Function split() is deprecated, %s(73)
  183. array(1) {
  184. [0]=>
  185. string(9) "1 2 3 4 5"
  186. }
  187. Arg value
  188. Error: 8192 - Function split() is deprecated, %s(73)
  189. array(1) {
  190. [0]=>
  191. string(9) "1 2 3 4 5"
  192. }
  193. Done