1--TEST--
2Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482)
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_pad(array $input, int $pad_size, mixed $pad_value)
8 * Description: Returns a copy of input array padded with pad_value to size pad_size
9 * Source code: ext/standard/array.c
10*/
11
12/*
13* Testing array_pad() function by passing values to $pad_size argument other than integers
14* and see that function outputs proper warning messages wherever expected.
15* The $input and $pad_value arguments passed are fixed values.
16*/
17
18echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n";
19
20// Initialise $input and $pad_value arguments
21$input = array(1, 2);
22$pad_value = 1;
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// get a class
29class classA
30{
31  public function __toString() {
32    return "Class A object";
33  }
34}
35
36//array of values to iterate over
37$pad_sizes = array(
38
39      // float data
40/*1*/  10.5,
41       -10.5,
42       12.3456789000e10,
43       -12.3456789000e10,
44       12.3456789000E-10,
45       .5,
46
47       // array data
48/*6*/  array(),
49       array(0),
50       array(1),
51       array(1, 2),
52       array('color' => 'red', 'item' => 'pen'),
53
54       // null data
55/*11*/ NULL,
56       null,
57
58       // boolean data
59/*13*/ true,
60       false,
61       TRUE,
62       FALSE,
63
64       // empty data
65/*17*/ "",
66       '',
67
68       // string data
69/*19*/ "string",
70       'string',
71
72       // object data
73/*21*/ new classA(),
74
75       // undefined data
76/*22*/ @$undefined_var,
77
78       // unset data
79/*23*/ @$unset_var,
80);
81
82// loop through each element of $pad_sizes to check the behavior of array_pad()
83$iterator = 1;
84foreach($pad_sizes as $pad_size) {
85  echo "-- Iteration $iterator --\n";
86  var_dump( array_pad($input, $pad_size, $pad_value) );
87  $iterator++;
88};
89
90echo "Done";
91?>
92--EXPECTF--
93*** Testing array_pad() : passing non integer values to $pad_size argument ***
94-- Iteration 1 --
95array(10) {
96  [0]=>
97  int(1)
98  [1]=>
99  int(2)
100  [2]=>
101  int(1)
102  [3]=>
103  int(1)
104  [4]=>
105  int(1)
106  [5]=>
107  int(1)
108  [6]=>
109  int(1)
110  [7]=>
111  int(1)
112  [8]=>
113  int(1)
114  [9]=>
115  int(1)
116}
117-- Iteration 2 --
118array(10) {
119  [0]=>
120  int(1)
121  [1]=>
122  int(1)
123  [2]=>
124  int(1)
125  [3]=>
126  int(1)
127  [4]=>
128  int(1)
129  [5]=>
130  int(1)
131  [6]=>
132  int(1)
133  [7]=>
134  int(1)
135  [8]=>
136  int(1)
137  [9]=>
138  int(2)
139}
140-- Iteration 3 --
141
142Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
143bool(false)
144-- Iteration 4 --
145
146Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
147bool(false)
148-- Iteration 5 --
149array(2) {
150  [0]=>
151  int(1)
152  [1]=>
153  int(2)
154}
155-- Iteration 6 --
156array(2) {
157  [0]=>
158  int(1)
159  [1]=>
160  int(2)
161}
162-- Iteration 7 --
163
164Warning: array_pad() expects parameter 2 to be integer, array given in %s on line %d
165NULL
166-- Iteration 8 --
167
168Warning: array_pad() expects parameter 2 to be integer, array given in %s on line %d
169NULL
170-- Iteration 9 --
171
172Warning: array_pad() expects parameter 2 to be integer, array given in %s on line %d
173NULL
174-- Iteration 10 --
175
176Warning: array_pad() expects parameter 2 to be integer, array given in %s on line %d
177NULL
178-- Iteration 11 --
179
180Warning: array_pad() expects parameter 2 to be integer, array given in %s on line %d
181NULL
182-- Iteration 12 --
183array(2) {
184  [0]=>
185  int(1)
186  [1]=>
187  int(2)
188}
189-- Iteration 13 --
190array(2) {
191  [0]=>
192  int(1)
193  [1]=>
194  int(2)
195}
196-- Iteration 14 --
197array(2) {
198  [0]=>
199  int(1)
200  [1]=>
201  int(2)
202}
203-- Iteration 15 --
204array(2) {
205  [0]=>
206  int(1)
207  [1]=>
208  int(2)
209}
210-- Iteration 16 --
211array(2) {
212  [0]=>
213  int(1)
214  [1]=>
215  int(2)
216}
217-- Iteration 17 --
218array(2) {
219  [0]=>
220  int(1)
221  [1]=>
222  int(2)
223}
224-- Iteration 18 --
225
226Warning: array_pad() expects parameter 2 to be integer, string given in %s on line %d
227NULL
228-- Iteration 19 --
229
230Warning: array_pad() expects parameter 2 to be integer, string given in %s on line %d
231NULL
232-- Iteration 20 --
233
234Warning: array_pad() expects parameter 2 to be integer, string given in %s on line %d
235NULL
236-- Iteration 21 --
237
238Warning: array_pad() expects parameter 2 to be integer, string given in %s on line %d
239NULL
240-- Iteration 22 --
241
242Warning: array_pad() expects parameter 2 to be integer, object given in %s on line %d
243NULL
244-- Iteration 23 --
245array(2) {
246  [0]=>
247  int(1)
248  [1]=>
249  int(2)
250}
251-- Iteration 24 --
252array(2) {
253  [0]=>
254  int(1)
255  [1]=>
256  int(2)
257}
258Done
259