1--TEST--
2Test array_intersect_assoc() function : usage variations - unexpected values for 'arr2' argument(Bug#43196)
3--FILE--
4<?php
5/* Prototype  : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
6 * Description: Returns the entries of arr1 that have values which are present in all the other arguments.
7 * Keys are used to do more restrictive check
8 * Source code: ext/standard/array.c
9*/
10
11/*
12* Testing array_intersect_assoc() function by passing values to $arr2 argument other than arrays
13* and see that function emits proper warning messages wherever expected.
14* The $arr1 argument passed is a fixed array.
15*/
16
17echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr2 argument ***\n";
18
19// array to be passsed to $arr1 as default argument
20$arr1 = array(1, 2);
21
22// additional array to be passed for intersection
23$arr3 = array(1, 2, "one" => 1, "two" => 2);
24
25// get an unset variable
26$unset_var = 10;
27unset ($unset_var);
28
29// get a class
30class classA
31{
32  public function __toString() {
33    return "Class A object";
34  }
35}
36
37// heredoc string
38$heredoc = <<<EOT
39hello world
40EOT;
41
42// get a resource variable
43$fp = fopen(__FILE__, "r");
44
45// unexpected values to be passed to $arr2 argument
46$arrays = array(
47
48       // int data
49/*1*/  0,
50       1,
51       12345,
52       -2345,
53
54       // float data
55/*5*/  10.5,
56       -10.5,
57       12.3456789000e10,
58       12.3456789000E-10,
59       .5,
60
61       // null data
62/*10*/ NULL,
63       null,
64
65       // boolean data
66/*12*/ true,
67       false,
68       TRUE,
69       FALSE,
70
71       // empty data
72/*16*/ "",
73       '',
74
75       // string data
76/*18*/ "string",
77       'string',
78       $heredoc,
79
80       // object data
81/*21*/ new classA(),
82
83       // undefined data
84/*22*/ @$undefined_var,
85
86       // unset data
87/*23*/ @$unset_var,
88
89       // resource variable
90/*24*/ $fp
91);
92
93// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
94$iterator = 1;
95foreach($arrays as $unexpected_value) {
96  echo "\n-- Iteration $iterator --";
97
98  // Calling array_intersect_assoc() with default arguments
99  var_dump( array_intersect_assoc($arr1,$unexpected_value) );
100
101  // Calling array_intersect_assoc() with more arguments
102  var_dump( array_intersect_assoc($arr1, $unexpected_value, $arr3) );
103
104  $iterator++;
105}
106
107// close the file resource used
108fclose($fp);
109
110echo "Done";
111?>
112--EXPECTF--
113*** Testing array_intersect_assoc() : Passing non-array values to $arr2 argument ***
114
115-- Iteration 1 --
116Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
117NULL
118
119Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
120NULL
121
122-- Iteration 2 --
123Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
124NULL
125
126Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
127NULL
128
129-- Iteration 3 --
130Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
131NULL
132
133Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
134NULL
135
136-- Iteration 4 --
137Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
138NULL
139
140Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
141NULL
142
143-- Iteration 5 --
144Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
145NULL
146
147Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
148NULL
149
150-- Iteration 6 --
151Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
152NULL
153
154Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
155NULL
156
157-- Iteration 7 --
158Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
159NULL
160
161Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
162NULL
163
164-- Iteration 8 --
165Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
166NULL
167
168Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
169NULL
170
171-- Iteration 9 --
172Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
173NULL
174
175Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
176NULL
177
178-- Iteration 10 --
179Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
180NULL
181
182Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
183NULL
184
185-- Iteration 11 --
186Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
187NULL
188
189Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
190NULL
191
192-- Iteration 12 --
193Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
194NULL
195
196Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
197NULL
198
199-- Iteration 13 --
200Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
201NULL
202
203Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
204NULL
205
206-- Iteration 14 --
207Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
208NULL
209
210Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
211NULL
212
213-- Iteration 15 --
214Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
215NULL
216
217Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
218NULL
219
220-- Iteration 16 --
221Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
222NULL
223
224Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
225NULL
226
227-- Iteration 17 --
228Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
229NULL
230
231Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
232NULL
233
234-- Iteration 18 --
235Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
236NULL
237
238Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
239NULL
240
241-- Iteration 19 --
242Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
243NULL
244
245Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
246NULL
247
248-- Iteration 20 --
249Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
250NULL
251
252Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
253NULL
254
255-- Iteration 21 --
256Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
257NULL
258
259Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
260NULL
261
262-- Iteration 22 --
263Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
264NULL
265
266Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
267NULL
268
269-- Iteration 23 --
270Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
271NULL
272
273Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
274NULL
275
276-- Iteration 24 --
277Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
278NULL
279
280Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d
281NULL
282Done
283