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