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