1--TEST--
2Test array_intersect_assoc() function : usage variations - unexpected values for 'arr1' 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 $arr1 argument other than arrays
13* and see that function emits proper warning messages wherever expected.
14* The $arr2 argument passed is a fixed array.
15*/
16
17echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr1 argument ***\n";
18
19// array to be passsed to $arr2 as default argument
20$arr2 = 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 $arr1 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($unexpected_value, $arr2) );
100
101  // Calling array_intersect_assoc() with more arguments
102  var_dump( array_intersect_assoc($unexpected_value, $arr2, $arr3) );
103  $iterator++;
104}
105
106// close the file resource used
107fclose($fp);
108
109echo "Done";
110?>
111--EXPECTF--
112*** Testing array_intersect_assoc() : Passing non-array values to $arr1 argument ***
113
114-- Iteration 1 --
115Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
116NULL
117
118Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
119NULL
120
121-- Iteration 2 --
122Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
123NULL
124
125Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
126NULL
127
128-- Iteration 3 --
129Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
130NULL
131
132Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
133NULL
134
135-- Iteration 4 --
136Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
137NULL
138
139Warning: array_intersect_assoc(): Expected parameter 1 to be an array, int given in %s on line %d
140NULL
141
142-- Iteration 5 --
143Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
144NULL
145
146Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
147NULL
148
149-- Iteration 6 --
150Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
151NULL
152
153Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
154NULL
155
156-- Iteration 7 --
157Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
158NULL
159
160Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
161NULL
162
163-- Iteration 8 --
164Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
165NULL
166
167Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
168NULL
169
170-- Iteration 9 --
171Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
172NULL
173
174Warning: array_intersect_assoc(): Expected parameter 1 to be an array, float given in %s on line %d
175NULL
176
177-- Iteration 10 --
178Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
179NULL
180
181Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
182NULL
183
184-- Iteration 11 --
185Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
186NULL
187
188Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
189NULL
190
191-- Iteration 12 --
192Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
193NULL
194
195Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
196NULL
197
198-- Iteration 13 --
199Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
200NULL
201
202Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
203NULL
204
205-- Iteration 14 --
206Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
207NULL
208
209Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
210NULL
211
212-- Iteration 15 --
213Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
214NULL
215
216Warning: array_intersect_assoc(): Expected parameter 1 to be an array, bool given in %s on line %d
217NULL
218
219-- Iteration 16 --
220Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
221NULL
222
223Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
224NULL
225
226-- Iteration 17 --
227Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
228NULL
229
230Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
231NULL
232
233-- Iteration 18 --
234Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
235NULL
236
237Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
238NULL
239
240-- Iteration 19 --
241Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
242NULL
243
244Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
245NULL
246
247-- Iteration 20 --
248Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
249NULL
250
251Warning: array_intersect_assoc(): Expected parameter 1 to be an array, string given in %s on line %d
252NULL
253
254-- Iteration 21 --
255Warning: array_intersect_assoc(): Expected parameter 1 to be an array, object given in %s on line %d
256NULL
257
258Warning: array_intersect_assoc(): Expected parameter 1 to be an array, object given in %s on line %d
259NULL
260
261-- Iteration 22 --
262Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
263NULL
264
265Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
266NULL
267
268-- Iteration 23 --
269Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
270NULL
271
272Warning: array_intersect_assoc(): Expected parameter 1 to be an array, null given in %s on line %d
273NULL
274
275-- Iteration 24 --
276Warning: array_intersect_assoc(): Expected parameter 1 to be an array, resource given in %s on line %d
277NULL
278
279Warning: array_intersect_assoc(): Expected parameter 1 to be an array, resource given in %s on line %d
280NULL
281Done
282