1--TEST--
2Test array_merge() function : usage variations - Pass different data types to $arr1 arg
3--FILE--
4<?php
5/* Prototype  : array array_merge(array $arr1, array $arr2 [, array $...])
6 * Description: Merges elements from passed arrays into one array
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Pass different data types as $arr1 argument to test behaviour
12 */
13
14echo "*** Testing array_merge() : usage variations ***\n";
15
16// Initialise function arguments not being substituted
17$arr2 = array (1, 2);
18
19//get an unset variable
20$unset_var = 10;
21unset ($unset_var);
22
23// get a class
24class classA
25{
26  public function __toString() {
27    return "Class A object";
28  }
29}
30
31// heredoc string
32$heredoc = <<<EOT
33hello world
34EOT;
35
36// get a resource variable
37$fp = fopen(__FILE__, "r");
38
39// unexpected values to be passed to $arr1 argument
40$inputs = array(
41
42       // int data
43/*1*/  0,
44       1,
45       12345,
46       -2345,
47
48       // float data
49/*5*/  10.5,
50       -10.5,
51       12.3456789000e10,
52       12.3456789000E-10,
53       .5,
54
55       // null data
56/*10*/ NULL,
57       null,
58
59       // boolean data
60/*12*/ true,
61       false,
62       TRUE,
63       FALSE,
64
65       // empty data
66/*16*/ "",
67       '',
68       array(),
69
70       // string data
71/*19*/ "string",
72       'string',
73       $heredoc,
74
75       // object data
76/*22*/ new classA(),
77
78       // undefined data
79/*23*/ @$undefined_var,
80
81       // unset data
82/*24*/ @$unset_var,
83
84       // resource variable
85/*25*/ $fp
86);
87
88// loop through each element of $inputs to check the behavior of array_merge()
89$iterator = 1;
90foreach($inputs as $input) {
91  echo "\n-- Iteration $iterator --\n";
92  var_dump( array_merge($input, $arr2) );
93  $iterator++;
94};
95
96fclose($fp);
97
98echo "Done";
99?>
100
101--EXPECTF--
102*** Testing array_merge() : usage variations ***
103
104-- Iteration 1 --
105
106Warning: array_merge(): Argument #1 is not an array in %s on line %d
107NULL
108
109-- Iteration 2 --
110
111Warning: array_merge(): Argument #1 is not an array in %s on line %d
112NULL
113
114-- Iteration 3 --
115
116Warning: array_merge(): Argument #1 is not an array in %s on line %d
117NULL
118
119-- Iteration 4 --
120
121Warning: array_merge(): Argument #1 is not an array in %s on line %d
122NULL
123
124-- Iteration 5 --
125
126Warning: array_merge(): Argument #1 is not an array in %s on line %d
127NULL
128
129-- Iteration 6 --
130
131Warning: array_merge(): Argument #1 is not an array in %s on line %d
132NULL
133
134-- Iteration 7 --
135
136Warning: array_merge(): Argument #1 is not an array in %s on line %d
137NULL
138
139-- Iteration 8 --
140
141Warning: array_merge(): Argument #1 is not an array in %s on line %d
142NULL
143
144-- Iteration 9 --
145
146Warning: array_merge(): Argument #1 is not an array in %s on line %d
147NULL
148
149-- Iteration 10 --
150
151Warning: array_merge(): Argument #1 is not an array in %s on line %d
152NULL
153
154-- Iteration 11 --
155
156Warning: array_merge(): Argument #1 is not an array in %s on line %d
157NULL
158
159-- Iteration 12 --
160
161Warning: array_merge(): Argument #1 is not an array in %s on line %d
162NULL
163
164-- Iteration 13 --
165
166Warning: array_merge(): Argument #1 is not an array in %s on line %d
167NULL
168
169-- Iteration 14 --
170
171Warning: array_merge(): Argument #1 is not an array in %s on line %d
172NULL
173
174-- Iteration 15 --
175
176Warning: array_merge(): Argument #1 is not an array in %s on line %d
177NULL
178
179-- Iteration 16 --
180
181Warning: array_merge(): Argument #1 is not an array in %s on line %d
182NULL
183
184-- Iteration 17 --
185
186Warning: array_merge(): Argument #1 is not an array in %s on line %d
187NULL
188
189-- Iteration 18 --
190array(2) {
191  [0]=>
192  int(1)
193  [1]=>
194  int(2)
195}
196
197-- Iteration 19 --
198
199Warning: array_merge(): Argument #1 is not an array in %s on line %d
200NULL
201
202-- Iteration 20 --
203
204Warning: array_merge(): Argument #1 is not an array in %s on line %d
205NULL
206
207-- Iteration 21 --
208
209Warning: array_merge(): Argument #1 is not an array in %s on line %d
210NULL
211
212-- Iteration 22 --
213
214Warning: array_merge(): Argument #1 is not an array in %s on line %d
215NULL
216
217-- Iteration 23 --
218
219Warning: array_merge(): Argument #1 is not an array in %s on line %d
220NULL
221
222-- Iteration 24 --
223
224Warning: array_merge(): Argument #1 is not an array in %s on line %d
225NULL
226
227-- Iteration 25 --
228
229Warning: array_merge(): Argument #1 is not an array in %s on line %d
230NULL
231Done
232