array_chunk_variation2.phpt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. --TEST--
  2. Test array_chunk() function : usage variations - unexpected values for 'size' argument
  3. --SKIPIF--
  4. <?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
  5. --FILE--
  6. <?php
  7. /* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys])
  8. * Description: Split array into chunks
  9. : Chunks an array into size large chunks
  10. * Source code: ext/standard/array.c
  11. */
  12. /*
  13. * Testing array_chunk() function with unexpected values for 'size' argument
  14. */
  15. echo "*** Testing array_chunk() : usage variations ***\n";
  16. // input array
  17. $input = array(1, 2);
  18. //get an unset variable
  19. $unset_var = 10;
  20. unset ($unset_var);
  21. //array of values to iterate over
  22. $values = array (
  23. // float data
  24. /*1*/ 10.5,
  25. -10.5,
  26. 10.5e10,
  27. 10.6E-10,
  28. .5,
  29. // array data
  30. /*6*/ array(),
  31. array(0),
  32. array(1),
  33. array(1, 2),
  34. array('color' => 'red', 'item' => 'pen'),
  35. // null data
  36. /*11*/ NULL,
  37. null,
  38. // boolean data
  39. /*13*/ true,
  40. false,
  41. TRUE,
  42. FALSE,
  43. // empty data
  44. /*17*/ "",
  45. '',
  46. // string data
  47. /*19*/ "string",
  48. 'string',
  49. // object data
  50. /*21*/ new stdclass(),
  51. // undefined data
  52. /*22*/ @$undefined_var,
  53. // unset data
  54. /*23*/ @$unset_var
  55. );
  56. // loop through each element of the array for size
  57. $count = 1;
  58. foreach($values as $value){
  59. echo "\n-- Iteration $count --\n";
  60. var_dump( array_chunk($input, $value) );
  61. var_dump( array_chunk($input, $value, true) );
  62. var_dump( array_chunk($input, $value, false) );
  63. $count++;
  64. }
  65. echo "Done";
  66. ?>
  67. --EXPECTF--
  68. *** Testing array_chunk() : usage variations ***
  69. -- Iteration 1 --
  70. array(1) {
  71. [0]=>
  72. array(2) {
  73. [0]=>
  74. int(1)
  75. [1]=>
  76. int(2)
  77. }
  78. }
  79. array(1) {
  80. [0]=>
  81. array(2) {
  82. [0]=>
  83. int(1)
  84. [1]=>
  85. int(2)
  86. }
  87. }
  88. array(1) {
  89. [0]=>
  90. array(2) {
  91. [0]=>
  92. int(1)
  93. [1]=>
  94. int(2)
  95. }
  96. }
  97. -- Iteration 2 --
  98. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  99. NULL
  100. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  101. NULL
  102. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  103. NULL
  104. -- Iteration 3 --
  105. array(1) {
  106. [0]=>
  107. array(2) {
  108. [0]=>
  109. int(1)
  110. [1]=>
  111. int(2)
  112. }
  113. }
  114. array(1) {
  115. [0]=>
  116. array(2) {
  117. [0]=>
  118. int(1)
  119. [1]=>
  120. int(2)
  121. }
  122. }
  123. array(1) {
  124. [0]=>
  125. array(2) {
  126. [0]=>
  127. int(1)
  128. [1]=>
  129. int(2)
  130. }
  131. }
  132. -- Iteration 4 --
  133. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  134. NULL
  135. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  136. NULL
  137. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  138. NULL
  139. -- Iteration 5 --
  140. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  141. NULL
  142. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  143. NULL
  144. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  145. NULL
  146. -- Iteration 6 --
  147. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  148. NULL
  149. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  150. NULL
  151. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  152. NULL
  153. -- Iteration 7 --
  154. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  155. NULL
  156. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  157. NULL
  158. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  159. NULL
  160. -- Iteration 8 --
  161. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  162. NULL
  163. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  164. NULL
  165. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  166. NULL
  167. -- Iteration 9 --
  168. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  169. NULL
  170. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  171. NULL
  172. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  173. NULL
  174. -- Iteration 10 --
  175. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  176. NULL
  177. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  178. NULL
  179. Warning: array_chunk() expects parameter 2 to be int, array given in %s on line %d
  180. NULL
  181. -- Iteration 11 --
  182. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  183. NULL
  184. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  185. NULL
  186. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  187. NULL
  188. -- Iteration 12 --
  189. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  190. NULL
  191. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  192. NULL
  193. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  194. NULL
  195. -- Iteration 13 --
  196. array(2) {
  197. [0]=>
  198. array(1) {
  199. [0]=>
  200. int(1)
  201. }
  202. [1]=>
  203. array(1) {
  204. [0]=>
  205. int(2)
  206. }
  207. }
  208. array(2) {
  209. [0]=>
  210. array(1) {
  211. [0]=>
  212. int(1)
  213. }
  214. [1]=>
  215. array(1) {
  216. [1]=>
  217. int(2)
  218. }
  219. }
  220. array(2) {
  221. [0]=>
  222. array(1) {
  223. [0]=>
  224. int(1)
  225. }
  226. [1]=>
  227. array(1) {
  228. [0]=>
  229. int(2)
  230. }
  231. }
  232. -- Iteration 14 --
  233. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  234. NULL
  235. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  236. NULL
  237. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  238. NULL
  239. -- Iteration 15 --
  240. array(2) {
  241. [0]=>
  242. array(1) {
  243. [0]=>
  244. int(1)
  245. }
  246. [1]=>
  247. array(1) {
  248. [0]=>
  249. int(2)
  250. }
  251. }
  252. array(2) {
  253. [0]=>
  254. array(1) {
  255. [0]=>
  256. int(1)
  257. }
  258. [1]=>
  259. array(1) {
  260. [1]=>
  261. int(2)
  262. }
  263. }
  264. array(2) {
  265. [0]=>
  266. array(1) {
  267. [0]=>
  268. int(1)
  269. }
  270. [1]=>
  271. array(1) {
  272. [0]=>
  273. int(2)
  274. }
  275. }
  276. -- Iteration 16 --
  277. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  278. NULL
  279. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  280. NULL
  281. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  282. NULL
  283. -- Iteration 17 --
  284. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  285. NULL
  286. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  287. NULL
  288. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  289. NULL
  290. -- Iteration 18 --
  291. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  292. NULL
  293. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  294. NULL
  295. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  296. NULL
  297. -- Iteration 19 --
  298. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  299. NULL
  300. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  301. NULL
  302. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  303. NULL
  304. -- Iteration 20 --
  305. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  306. NULL
  307. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  308. NULL
  309. Warning: array_chunk() expects parameter 2 to be int, string given in %s on line %d
  310. NULL
  311. -- Iteration 21 --
  312. Warning: array_chunk() expects parameter 2 to be int, object given in %s on line %d
  313. NULL
  314. Warning: array_chunk() expects parameter 2 to be int, object given in %s on line %d
  315. NULL
  316. Warning: array_chunk() expects parameter 2 to be int, object given in %s on line %d
  317. NULL
  318. -- Iteration 22 --
  319. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  320. NULL
  321. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  322. NULL
  323. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  324. NULL
  325. -- Iteration 23 --
  326. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  327. NULL
  328. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  329. NULL
  330. Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
  331. NULL
  332. Done