1--TEST--
2Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument
3--FILE--
4<?php
5/*
6 * Passing non array values to 'arr2' 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 \$arr2 argument ***\n";
11
12// initialise the first argument
13$arr1 = array(1, array("hello", 'world'));
14
15//get an unset variable
16$unset_var = 10;
17unset($unset_var);
18
19class A
20{
21//  public $var = 10;
22  public function __toString() {
23    return "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// unexpected values to be passed to $arr2 argument
36$arrays = array (
37
38       // int data
39/*1*/  0,
40       1,
41       12345,
42       -2345,
43
44       // float data
45/*5*/  10.5,
46       -10.5,
47       12.3456789000e10,
48       12.3456789000E-10,
49       .5,
50
51       // null data
52/*10*/ NULL,
53       null,
54
55       // boolean data
56/*12*/ true,
57       false,
58       TRUE,
59       FALSE,
60
61       // empty data
62/*16*/ "",
63       '',
64
65       // string data
66/*18*/ "string",
67       'string',
68       $heredoc,
69
70       // undefined data
71/*21*/ @$undefined_var,
72
73       // unset data
74/*22*/ @$unset_var,
75
76       // resource variable
77/*23*/ $fp,
78
79       // object data
80/*24*/ new A()
81);
82
83// loop through each element of $arrays and check the behavior of array_merge_recursive()
84$iterator = 1;
85foreach($arrays as $arr2) {
86    echo "\n-- Iteration $iterator --";
87    try {
88        var_dump( array_merge_recursive($arr1, $arr2) );
89    } catch (TypeError $e) {
90        echo $e->getMessage(), "\n";
91    }
92    $iterator++;
93}
94
95// close the file resource used
96fclose($fp);
97
98echo "Done";
99?>
100--EXPECT--
101*** Testing array_merge_recursive() : Passing non array values to $arr2 argument ***
102
103-- Iteration 1 --array_merge_recursive(): Argument #2 must be of type array, int given
104
105-- Iteration 2 --array_merge_recursive(): Argument #2 must be of type array, int given
106
107-- Iteration 3 --array_merge_recursive(): Argument #2 must be of type array, int given
108
109-- Iteration 4 --array_merge_recursive(): Argument #2 must be of type array, int given
110
111-- Iteration 5 --array_merge_recursive(): Argument #2 must be of type array, float given
112
113-- Iteration 6 --array_merge_recursive(): Argument #2 must be of type array, float given
114
115-- Iteration 7 --array_merge_recursive(): Argument #2 must be of type array, float given
116
117-- Iteration 8 --array_merge_recursive(): Argument #2 must be of type array, float given
118
119-- Iteration 9 --array_merge_recursive(): Argument #2 must be of type array, float given
120
121-- Iteration 10 --array_merge_recursive(): Argument #2 must be of type array, null given
122
123-- Iteration 11 --array_merge_recursive(): Argument #2 must be of type array, null given
124
125-- Iteration 12 --array_merge_recursive(): Argument #2 must be of type array, true given
126
127-- Iteration 13 --array_merge_recursive(): Argument #2 must be of type array, false given
128
129-- Iteration 14 --array_merge_recursive(): Argument #2 must be of type array, true given
130
131-- Iteration 15 --array_merge_recursive(): Argument #2 must be of type array, false given
132
133-- Iteration 16 --array_merge_recursive(): Argument #2 must be of type array, string given
134
135-- Iteration 17 --array_merge_recursive(): Argument #2 must be of type array, string given
136
137-- Iteration 18 --array_merge_recursive(): Argument #2 must be of type array, string given
138
139-- Iteration 19 --array_merge_recursive(): Argument #2 must be of type array, string given
140
141-- Iteration 20 --array_merge_recursive(): Argument #2 must be of type array, string given
142
143-- Iteration 21 --array_merge_recursive(): Argument #2 must be of type array, null given
144
145-- Iteration 22 --array_merge_recursive(): Argument #2 must be of type array, null given
146
147-- Iteration 23 --array_merge_recursive(): Argument #2 must be of type array, resource given
148
149-- Iteration 24 --array_merge_recursive(): Argument #2 must be of type array, A given
150Done
151