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