1--TEST--
2Test array_intersect_assoc() function : usage variations - unexpected values for 'array2' argument(Bug#43196)
3--FILE--
4<?php
5/*
6* Testing array_intersect_assoc() function by passing values to $array2 argument other than arrays
7* and see that function emits proper warning messages wherever expected.
8* The $array1 argument passed is a fixed array.
9*/
10
11echo "*** Testing array_intersect_assoc() : Passing non-array values to \$array2 argument ***\n";
12
13// array to be passsed to $array1 as default argument
14$array1 = array(1, 2);
15
16// additional array to be passed for intersection
17$arr3 = array(1, 2, "one" => 1, "two" => 2);
18
19// get an unset variable
20$unset_var = 10;
21unset ($unset_var);
22
23// get a class
24class classA
25{
26  public function __toString() {
27    return "Class A object";
28  }
29}
30
31// heredoc string
32$heredoc = <<<EOT
33hello world
34EOT;
35
36// get a resource variable
37$fp = fopen(__FILE__, "r");
38
39// unexpected values to be passed to $array2 argument
40$arrays = array(
41
42       // int data
43/*1*/  0,
44       1,
45       12345,
46       -2345,
47
48       // float data
49/*5*/  10.5,
50       -10.5,
51       12.3456789000e10,
52       12.3456789000E-10,
53       .5,
54
55       // null data
56/*10*/ NULL,
57       null,
58
59       // boolean data
60/*12*/ true,
61       false,
62       TRUE,
63       FALSE,
64
65       // empty data
66/*16*/ "",
67       '',
68
69       // string data
70/*18*/ "string",
71       'string',
72       $heredoc,
73
74       // object data
75/*21*/ new classA(),
76
77       // undefined data
78/*22*/ @$undefined_var,
79
80       // unset data
81/*23*/ @$unset_var,
82
83       // resource variable
84/*24*/ $fp
85);
86
87// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc()
88$iterator = 1;
89foreach($arrays as $unexpected_value) {
90    echo "\n-- Iteration $iterator --";
91
92    // Calling array_intersect_assoc() with default arguments
93    try {
94        var_dump( array_intersect_assoc($array1,$unexpected_value) );
95    } catch (TypeError $e) {
96        echo $e->getMessage(), "\n";
97    }
98
99    // Calling array_intersect_assoc() with more arguments
100    try {
101        var_dump( array_intersect_assoc($array1, $unexpected_value, $arr3) );
102    } catch (TypeError $e) {
103        echo $e->getMessage(), "\n";
104    }
105
106    $iterator++;
107}
108
109// close the file resource used
110fclose($fp);
111
112echo "Done";
113?>
114--EXPECT--
115*** Testing array_intersect_assoc() : Passing non-array values to $array2 argument ***
116
117-- Iteration 1 --array_intersect_assoc(): Argument #2 must be of type array, int given
118array_intersect_assoc(): Argument #2 must be of type array, int given
119
120-- Iteration 2 --array_intersect_assoc(): Argument #2 must be of type array, int given
121array_intersect_assoc(): Argument #2 must be of type array, int given
122
123-- Iteration 3 --array_intersect_assoc(): Argument #2 must be of type array, int given
124array_intersect_assoc(): Argument #2 must be of type array, int given
125
126-- Iteration 4 --array_intersect_assoc(): Argument #2 must be of type array, int given
127array_intersect_assoc(): Argument #2 must be of type array, int given
128
129-- Iteration 5 --array_intersect_assoc(): Argument #2 must be of type array, float given
130array_intersect_assoc(): Argument #2 must be of type array, float given
131
132-- Iteration 6 --array_intersect_assoc(): Argument #2 must be of type array, float given
133array_intersect_assoc(): Argument #2 must be of type array, float given
134
135-- Iteration 7 --array_intersect_assoc(): Argument #2 must be of type array, float given
136array_intersect_assoc(): Argument #2 must be of type array, float given
137
138-- Iteration 8 --array_intersect_assoc(): Argument #2 must be of type array, float given
139array_intersect_assoc(): Argument #2 must be of type array, float given
140
141-- Iteration 9 --array_intersect_assoc(): Argument #2 must be of type array, float given
142array_intersect_assoc(): Argument #2 must be of type array, float given
143
144-- Iteration 10 --array_intersect_assoc(): Argument #2 must be of type array, null given
145array_intersect_assoc(): Argument #2 must be of type array, null given
146
147-- Iteration 11 --array_intersect_assoc(): Argument #2 must be of type array, null given
148array_intersect_assoc(): Argument #2 must be of type array, null given
149
150-- Iteration 12 --array_intersect_assoc(): Argument #2 must be of type array, true given
151array_intersect_assoc(): Argument #2 must be of type array, true given
152
153-- Iteration 13 --array_intersect_assoc(): Argument #2 must be of type array, false given
154array_intersect_assoc(): Argument #2 must be of type array, false given
155
156-- Iteration 14 --array_intersect_assoc(): Argument #2 must be of type array, true given
157array_intersect_assoc(): Argument #2 must be of type array, true given
158
159-- Iteration 15 --array_intersect_assoc(): Argument #2 must be of type array, false given
160array_intersect_assoc(): Argument #2 must be of type array, false given
161
162-- Iteration 16 --array_intersect_assoc(): Argument #2 must be of type array, string given
163array_intersect_assoc(): Argument #2 must be of type array, string given
164
165-- Iteration 17 --array_intersect_assoc(): Argument #2 must be of type array, string given
166array_intersect_assoc(): Argument #2 must be of type array, string given
167
168-- Iteration 18 --array_intersect_assoc(): Argument #2 must be of type array, string given
169array_intersect_assoc(): Argument #2 must be of type array, string given
170
171-- Iteration 19 --array_intersect_assoc(): Argument #2 must be of type array, string given
172array_intersect_assoc(): Argument #2 must be of type array, string given
173
174-- Iteration 20 --array_intersect_assoc(): Argument #2 must be of type array, string given
175array_intersect_assoc(): Argument #2 must be of type array, string given
176
177-- Iteration 21 --array_intersect_assoc(): Argument #2 must be of type array, classA given
178array_intersect_assoc(): Argument #2 must be of type array, classA given
179
180-- Iteration 22 --array_intersect_assoc(): Argument #2 must be of type array, null given
181array_intersect_assoc(): Argument #2 must be of type array, null given
182
183-- Iteration 23 --array_intersect_assoc(): Argument #2 must be of type array, null given
184array_intersect_assoc(): Argument #2 must be of type array, null given
185
186-- Iteration 24 --array_intersect_assoc(): Argument #2 must be of type array, resource given
187array_intersect_assoc(): Argument #2 must be of type array, resource given
188Done
189