1--TEST--
2Test array_diff() function : usage variations - unexpected values for 'arr2' argument
3--FILE--
4<?php
5/* Prototype  : array array_diff(array $arr1, array $arr2 [, array ...])
6 * Description: Returns the entries of $arr1 that have values which are
7 * not present in any of the others arguments.
8 * Source code: ext/standard/array.c
9 */
10
11/*
12 * Test array_diff by passing non array values in place of $arr2
13 */
14
15echo "*** Testing array_diff() : usage variations ***\n";
16
17$array = array(1, 2, 3);
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 $input argument
40$inputs = 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       // binary data
75/*21*/ b"binary",
76	   (binary)"binary",
77
78       // object data
79/*23*/ new classA(),
80
81       // undefined data
82/*24*/ @$undefined_var,
83
84       // unset data
85/*25*/ @$unset_var,
86
87       // resource variable
88/*26*/ $fp
89);
90
91// loop through each element of $inputs to check the behavior of array_diff
92$iterator = 1;
93foreach($inputs as $input) {
94  echo "\n-- Iteration $iterator --";
95  var_dump( array_diff($array, $input));
96  $iterator++;
97};
98fclose($fp);
99echo "Done";
100?>
101--EXPECTF--
102*** Testing array_diff() : usage variations ***
103
104-- Iteration 1 --
105Warning: array_diff(): Argument #2 is not an array in %s on line %d
106NULL
107
108-- Iteration 2 --
109Warning: array_diff(): Argument #2 is not an array in %s on line %d
110NULL
111
112-- Iteration 3 --
113Warning: array_diff(): Argument #2 is not an array in %s on line %d
114NULL
115
116-- Iteration 4 --
117Warning: array_diff(): Argument #2 is not an array in %s on line %d
118NULL
119
120-- Iteration 5 --
121Warning: array_diff(): Argument #2 is not an array in %s on line %d
122NULL
123
124-- Iteration 6 --
125Warning: array_diff(): Argument #2 is not an array in %s on line %d
126NULL
127
128-- Iteration 7 --
129Warning: array_diff(): Argument #2 is not an array in %s on line %d
130NULL
131
132-- Iteration 8 --
133Warning: array_diff(): Argument #2 is not an array in %s on line %d
134NULL
135
136-- Iteration 9 --
137Warning: array_diff(): Argument #2 is not an array in %s on line %d
138NULL
139
140-- Iteration 10 --
141Warning: array_diff(): Argument #2 is not an array in %s on line %d
142NULL
143
144-- Iteration 11 --
145Warning: array_diff(): Argument #2 is not an array in %s on line %d
146NULL
147
148-- Iteration 12 --
149Warning: array_diff(): Argument #2 is not an array in %s on line %d
150NULL
151
152-- Iteration 13 --
153Warning: array_diff(): Argument #2 is not an array in %s on line %d
154NULL
155
156-- Iteration 14 --
157Warning: array_diff(): Argument #2 is not an array in %s on line %d
158NULL
159
160-- Iteration 15 --
161Warning: array_diff(): Argument #2 is not an array in %s on line %d
162NULL
163
164-- Iteration 16 --
165Warning: array_diff(): Argument #2 is not an array in %s on line %d
166NULL
167
168-- Iteration 17 --
169Warning: array_diff(): Argument #2 is not an array in %s on line %d
170NULL
171
172-- Iteration 18 --
173Warning: array_diff(): Argument #2 is not an array in %s on line %d
174NULL
175
176-- Iteration 19 --
177Warning: array_diff(): Argument #2 is not an array in %s on line %d
178NULL
179
180-- Iteration 20 --
181Warning: array_diff(): Argument #2 is not an array in %s on line %d
182NULL
183
184-- Iteration 21 --
185Warning: array_diff(): Argument #2 is not an array in %s on line %d
186NULL
187
188-- Iteration 22 --
189Warning: array_diff(): Argument #2 is not an array in %s on line %d
190NULL
191
192-- Iteration 23 --
193Warning: array_diff(): Argument #2 is not an array in %s on line %d
194NULL
195
196-- Iteration 24 --
197Warning: array_diff(): Argument #2 is not an array in %s on line %d
198NULL
199
200-- Iteration 25 --
201Warning: array_diff(): Argument #2 is not an array in %s on line %d
202NULL
203
204-- Iteration 26 --
205Warning: array_diff(): Argument #2 is not an array in %s on line %d
206NULL
207Done