1--TEST--
2Test array_merge() function : usage variations - Pass different data types as $arr2 arg
3--FILE--
4<?php
5/*
6 * Pass different data types as $arr2 argument to array_merge() to test behaviour
7 */
8
9echo "*** Testing array_merge() : usage variations ***\n";
10
11// Initialise function arguments not being substituted
12$arr1 = array (1, 2);
13
14//get an unset variable
15$unset_var = 10;
16unset ($unset_var);
17
18// get a class
19class classA
20{
21  public function __toString() {
22    return "Class A object";
23  }
24}
25
26// heredoc string
27$heredoc = <<<EOT
28hello world
29EOT;
30
31// get a resource variable
32$fp = fopen(__FILE__, "r");
33
34// unexpected values to be passed to $arr2 argument
35$inputs = array(
36
37       // int data
38/*1*/  0,
39       1,
40       12345,
41       -2345,
42
43       // float data
44/*5*/  10.5,
45       -10.5,
46       12.3456789000e10,
47       12.3456789000E-10,
48       .5,
49
50       // null data
51/*10*/ NULL,
52       null,
53
54       // boolean data
55/*12*/ true,
56       false,
57       TRUE,
58       FALSE,
59
60       // empty data
61/*16*/ "",
62       '',
63       array(),
64
65       // string data
66/*19*/ "string",
67       'string',
68       $heredoc,
69
70       // object data
71/*22*/ new classA(),
72
73       // undefined data
74/*23*/ @$undefined_var,
75
76       // unset data
77/*24*/ @$unset_var,
78
79       // resource variable
80/*25*/ $fp
81);
82
83// loop through each element of $inputs to check the behavior of array_merge()
84$iterator = 1;
85foreach($inputs as $input) {
86    echo "\n-- Iteration $iterator --\n";
87    try {
88        var_dump( array_merge($arr1, $input) );
89    } catch (TypeError $e) {
90        echo $e->getMessage(), "\n";
91    }
92    $iterator++;
93};
94
95fclose($fp);
96
97echo "Done";
98?>
99--EXPECT--
100*** Testing array_merge() : usage variations ***
101
102-- Iteration 1 --
103array_merge(): Argument #2 must be of type array, int given
104
105-- Iteration 2 --
106array_merge(): Argument #2 must be of type array, int given
107
108-- Iteration 3 --
109array_merge(): Argument #2 must be of type array, int given
110
111-- Iteration 4 --
112array_merge(): Argument #2 must be of type array, int given
113
114-- Iteration 5 --
115array_merge(): Argument #2 must be of type array, float given
116
117-- Iteration 6 --
118array_merge(): Argument #2 must be of type array, float given
119
120-- Iteration 7 --
121array_merge(): Argument #2 must be of type array, float given
122
123-- Iteration 8 --
124array_merge(): Argument #2 must be of type array, float given
125
126-- Iteration 9 --
127array_merge(): Argument #2 must be of type array, float given
128
129-- Iteration 10 --
130array_merge(): Argument #2 must be of type array, null given
131
132-- Iteration 11 --
133array_merge(): Argument #2 must be of type array, null given
134
135-- Iteration 12 --
136array_merge(): Argument #2 must be of type array, true given
137
138-- Iteration 13 --
139array_merge(): Argument #2 must be of type array, false given
140
141-- Iteration 14 --
142array_merge(): Argument #2 must be of type array, true given
143
144-- Iteration 15 --
145array_merge(): Argument #2 must be of type array, false given
146
147-- Iteration 16 --
148array_merge(): Argument #2 must be of type array, string given
149
150-- Iteration 17 --
151array_merge(): Argument #2 must be of type array, string given
152
153-- Iteration 18 --
154array(2) {
155  [0]=>
156  int(1)
157  [1]=>
158  int(2)
159}
160
161-- Iteration 19 --
162array_merge(): Argument #2 must be of type array, string given
163
164-- Iteration 20 --
165array_merge(): Argument #2 must be of type array, string given
166
167-- Iteration 21 --
168array_merge(): Argument #2 must be of type array, string given
169
170-- Iteration 22 --
171array_merge(): Argument #2 must be of type array, classA given
172
173-- Iteration 23 --
174array_merge(): Argument #2 must be of type array, null given
175
176-- Iteration 24 --
177array_merge(): Argument #2 must be of type array, null given
178
179-- Iteration 25 --
180array_merge(): Argument #2 must be of type array, resource given
181Done
182