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