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