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