1--TEST--
2Test array_intersect_assoc() function : usage variations - unexpected values for 'array1' argument(Bug#43196)
3--FILE--
4<?php
5/*
6* Testing array_intersect_assoc() function by passing values to $array1 argument other than arrays
7* and see that function emits proper warning messages wherever expected.
8* The $array2 argument passed is a fixed array.
9*/
10
11echo "*** Testing array_intersect_assoc() : Passing non-array values to \$array1 argument ***\n";
12
13// array to be passsed to $array2 as default argument
14$array2 = array(1, 2);
15
16// additional array to be passed for intersection
17$arr3 = array(1, 2, "one" => 1, "two" => 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 $array1 argument
40$arrays = 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
69       // string data
70/*18*/ "string",
71       'string',
72       $heredoc,
73
74       // object data
75/*21*/ new classA(),
76
77       // undefined data
78/*22*/ @$undefined_var,
79
80       // unset data
81/*23*/ @$unset_var,
82
83       // resource variable
84/*24*/ $fp
85);
86
87// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc()
88$iterator = 1;
89foreach($arrays as $unexpected_value) {
90    echo "\n-- Iteration $iterator --";
91
92    // Calling array_intersect_assoc() with default arguments
93    try {
94        var_dump( array_intersect_assoc($unexpected_value, $array2) );
95    } catch (TypeError $e) {
96        echo $e->getMessage(), "\n";
97    }
98
99    // Calling array_intersect_assoc() with more arguments
100    try {
101        var_dump( array_intersect_assoc($unexpected_value, $array2, $arr3) );
102    } catch (TypeError $e) {
103        echo $e->getMessage(), "\n";
104    }
105    $iterator++;
106}
107
108// close the file resource used
109fclose($fp);
110
111echo "Done";
112?>
113--EXPECT--
114*** Testing array_intersect_assoc() : Passing non-array values to $array1 argument ***
115
116-- Iteration 1 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
117array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
118
119-- Iteration 2 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
120array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
121
122-- Iteration 3 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
123array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
124
125-- Iteration 4 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
126array_intersect_assoc(): Argument #1 ($array) must be of type array, int given
127
128-- Iteration 5 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
129array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
130
131-- Iteration 6 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
132array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
133
134-- Iteration 7 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
135array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
136
137-- Iteration 8 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
138array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
139
140-- Iteration 9 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
141array_intersect_assoc(): Argument #1 ($array) must be of type array, float given
142
143-- Iteration 10 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
144array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
145
146-- Iteration 11 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
147array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
148
149-- Iteration 12 --array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
150array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
151
152-- Iteration 13 --array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
153array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
154
155-- Iteration 14 --array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
156array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
157
158-- Iteration 15 --array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
159array_intersect_assoc(): Argument #1 ($array) must be of type array, bool given
160
161-- Iteration 16 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
162array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
163
164-- Iteration 17 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
165array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
166
167-- Iteration 18 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
168array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
169
170-- Iteration 19 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
171array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
172
173-- Iteration 20 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
174array_intersect_assoc(): Argument #1 ($array) must be of type array, string given
175
176-- Iteration 21 --array_intersect_assoc(): Argument #1 ($array) must be of type array, classA given
177array_intersect_assoc(): Argument #1 ($array) must be of type array, classA given
178
179-- Iteration 22 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
180array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
181
182-- Iteration 23 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
183array_intersect_assoc(): Argument #1 ($array) must be of type array, null given
184
185-- Iteration 24 --array_intersect_assoc(): Argument #1 ($array) must be of type array, resource given
186array_intersect_assoc(): Argument #1 ($array) must be of type array, resource given
187Done
188