1--TEST--
2Test array_intersect_key() function : usage variation - Passing unexpected values to optional argument
3--FILE--
4<?php
5/* Prototype  : array array_intersect_key(array arr1, array arr2 [, array ...])
6 * Description: Returns the entries of arr1 that have keys which are present in all the other arguments.
7 * Source code: ext/standard/array.c
8 */
9
10echo "*** Testing array_intersect_key() : usage variation ***\n";
11
12// Initialise function arguments not being substituted (if any)
13$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
14$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
15
16//get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20//resource variable
21$fp = fopen(__FILE__, "r");
22
23// define some classes
24class classWithToString
25{
26	public function __toString() {
27		return "Class A object";
28	}
29}
30
31class classWithoutToString
32{
33}
34
35// heredoc string
36$heredoc = <<<EOT
37hello world
38EOT;
39
40// add arrays
41$index_array = array (1, 2, 3);
42$assoc_array = array ('one' => 1, 'two' => 2);
43
44//array of values to iterate over
45$inputs = array(
46
47      // int data
48      'int 0' => 0,
49      'int 1' => 1,
50      'int 12345' => 12345,
51      'int -12345' => -12345,
52
53      // float data
54      'float 10.5' => 10.5,
55      'float -10.5' => -10.5,
56      'float 12.3456789000e10' => 12.3456789000e10,
57      'float -12.3456789000e10' => -12.3456789000e10,
58      'float .5' => .5,
59
60      // null data
61      'uppercase NULL' => NULL,
62      'lowercase null' => null,
63
64      // boolean data
65      'lowercase true' => true,
66      'lowercase false' =>false,
67      'uppercase TRUE' =>TRUE,
68      'uppercase FALSE' =>FALSE,
69
70      // empty data
71      'empty string DQ' => "",
72      'empty string SQ' => '',
73
74      // string data
75      'string DQ' => "string",
76      'string SQ' => 'string',
77      'mixed case string' => "sTrInG",
78      'heredoc' => $heredoc,
79
80      // object data
81      'instance of classWithToString' => new classWithToString(),
82      'instance of classWithoutToString' => new classWithoutToString(),
83
84      // undefined data
85      'undefined var' => @$undefined_var,
86
87      // unset data
88      'unset var' => @$unset_var,
89
90      // resource data
91      'resource var' => $fp,
92);
93
94// loop through each element of the array for arr2
95foreach($inputs as $key =>$value) {
96      echo "\n--$key--\n";
97      var_dump( array_intersect_key($array1, $array2, $value) );
98}
99
100fclose($fp);
101?>
102===DONE===
103--EXPECTF--
104*** Testing array_intersect_key() : usage variation ***
105
106--int 0--
107
108Warning: array_intersect_key(): Expected parameter 3 to be an array, int given in %s on line %d
109NULL
110
111--int 1--
112
113Warning: array_intersect_key(): Expected parameter 3 to be an array, int given in %s on line %d
114NULL
115
116--int 12345--
117
118Warning: array_intersect_key(): Expected parameter 3 to be an array, int given in %s on line %d
119NULL
120
121--int -12345--
122
123Warning: array_intersect_key(): Expected parameter 3 to be an array, int given in %s on line %d
124NULL
125
126--float 10.5--
127
128Warning: array_intersect_key(): Expected parameter 3 to be an array, float given in %s on line %d
129NULL
130
131--float -10.5--
132
133Warning: array_intersect_key(): Expected parameter 3 to be an array, float given in %s on line %d
134NULL
135
136--float 12.3456789000e10--
137
138Warning: array_intersect_key(): Expected parameter 3 to be an array, float given in %s on line %d
139NULL
140
141--float -12.3456789000e10--
142
143Warning: array_intersect_key(): Expected parameter 3 to be an array, float given in %s on line %d
144NULL
145
146--float .5--
147
148Warning: array_intersect_key(): Expected parameter 3 to be an array, float given in %s on line %d
149NULL
150
151--uppercase NULL--
152
153Warning: array_intersect_key(): Expected parameter 3 to be an array, null given in %s on line %d
154NULL
155
156--lowercase null--
157
158Warning: array_intersect_key(): Expected parameter 3 to be an array, null given in %s on line %d
159NULL
160
161--lowercase true--
162
163Warning: array_intersect_key(): Expected parameter 3 to be an array, bool given in %s on line %d
164NULL
165
166--lowercase false--
167
168Warning: array_intersect_key(): Expected parameter 3 to be an array, bool given in %s on line %d
169NULL
170
171--uppercase TRUE--
172
173Warning: array_intersect_key(): Expected parameter 3 to be an array, bool given in %s on line %d
174NULL
175
176--uppercase FALSE--
177
178Warning: array_intersect_key(): Expected parameter 3 to be an array, bool given in %s on line %d
179NULL
180
181--empty string DQ--
182
183Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
184NULL
185
186--empty string SQ--
187
188Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
189NULL
190
191--string DQ--
192
193Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
194NULL
195
196--string SQ--
197
198Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
199NULL
200
201--mixed case string--
202
203Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
204NULL
205
206--heredoc--
207
208Warning: array_intersect_key(): Expected parameter 3 to be an array, string given in %s on line %d
209NULL
210
211--instance of classWithToString--
212
213Warning: array_intersect_key(): Expected parameter 3 to be an array, object given in %s on line %d
214NULL
215
216--instance of classWithoutToString--
217
218Warning: array_intersect_key(): Expected parameter 3 to be an array, object given in %s on line %d
219NULL
220
221--undefined var--
222
223Warning: array_intersect_key(): Expected parameter 3 to be an array, null given in %s on line %d
224NULL
225
226--unset var--
227
228Warning: array_intersect_key(): Expected parameter 3 to be an array, null given in %s on line %d
229NULL
230
231--resource var--
232
233Warning: array_intersect_key(): Expected parameter 3 to be an array, resource given in %s on line %d
234NULL
235===DONE===
236