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