1--TEST--
2Test array_diff() function : usage variations - unexpected values for 'array1' argument
3--FILE--
4<?php
5/*
6 * Test array_diff by passing non array values in place of $array1
7 */
8
9echo "*** Testing array_diff() : usage variations ***\n";
10
11$array = array(1, 2, 3);
12
13//get an unset variable
14$unset_var = 10;
15unset ($unset_var);
16
17// get a class
18class classA
19{
20  public function __toString() {
21    return "Class A object";
22  }
23}
24
25// heredoc string
26$heredoc = <<<EOT
27hello world
28EOT;
29
30// get a resource variable
31$fp = fopen(__FILE__, "r");
32
33// unexpected values to be passed to $input argument
34$inputs = array(
35
36       // int data
37/*1*/  0,
38       1,
39       12345,
40       -2345,
41
42       // float data
43/*5*/  10.5,
44       -10.5,
45       12.3456789000e10,
46       12.3456789000E-10,
47       .5,
48
49       // null data
50/*10*/ NULL,
51       null,
52
53       // boolean data
54/*12*/ true,
55       false,
56       TRUE,
57       FALSE,
58
59       // empty data
60/*16*/ "",
61       '',
62
63       // string data
64/*18*/ "string",
65       'string',
66       $heredoc,
67
68       // binary data
69/*21*/ b"binary",
70       (binary)"binary",
71
72       // object data
73/*23*/ new classA(),
74
75       // undefined data
76/*24*/ @$undefined_var,
77
78       // unset data
79/*25*/ @$unset_var,
80
81       // resource variable
82/*26*/ $fp
83);
84
85// loop through each element of $inputs to check the behavior of array_diff
86$iterator = 1;
87foreach($inputs as $input) {
88    echo "\n-- Iteration $iterator --";
89    try {
90        var_dump( array_diff($input, $array));
91    } catch (TypeError $e) {
92        echo $e->getMessage(), "\n";
93    }
94    $iterator++;
95};
96
97fclose($fp);
98echo "Done";
99?>
100--EXPECT--
101*** Testing array_diff() : usage variations ***
102
103-- Iteration 1 --array_diff(): Argument #1 ($array) must be of type array, int given
104
105-- Iteration 2 --array_diff(): Argument #1 ($array) must be of type array, int given
106
107-- Iteration 3 --array_diff(): Argument #1 ($array) must be of type array, int given
108
109-- Iteration 4 --array_diff(): Argument #1 ($array) must be of type array, int given
110
111-- Iteration 5 --array_diff(): Argument #1 ($array) must be of type array, float given
112
113-- Iteration 6 --array_diff(): Argument #1 ($array) must be of type array, float given
114
115-- Iteration 7 --array_diff(): Argument #1 ($array) must be of type array, float given
116
117-- Iteration 8 --array_diff(): Argument #1 ($array) must be of type array, float given
118
119-- Iteration 9 --array_diff(): Argument #1 ($array) must be of type array, float given
120
121-- Iteration 10 --array_diff(): Argument #1 ($array) must be of type array, null given
122
123-- Iteration 11 --array_diff(): Argument #1 ($array) must be of type array, null given
124
125-- Iteration 12 --array_diff(): Argument #1 ($array) must be of type array, true given
126
127-- Iteration 13 --array_diff(): Argument #1 ($array) must be of type array, false given
128
129-- Iteration 14 --array_diff(): Argument #1 ($array) must be of type array, true given
130
131-- Iteration 15 --array_diff(): Argument #1 ($array) must be of type array, false given
132
133-- Iteration 16 --array_diff(): Argument #1 ($array) must be of type array, string given
134
135-- Iteration 17 --array_diff(): Argument #1 ($array) must be of type array, string given
136
137-- Iteration 18 --array_diff(): Argument #1 ($array) must be of type array, string given
138
139-- Iteration 19 --array_diff(): Argument #1 ($array) must be of type array, string given
140
141-- Iteration 20 --array_diff(): Argument #1 ($array) must be of type array, string given
142
143-- Iteration 21 --array_diff(): Argument #1 ($array) must be of type array, string given
144
145-- Iteration 22 --array_diff(): Argument #1 ($array) must be of type array, string given
146
147-- Iteration 23 --array_diff(): Argument #1 ($array) must be of type array, classA given
148
149-- Iteration 24 --array_diff(): Argument #1 ($array) must be of type array, null given
150
151-- Iteration 25 --array_diff(): Argument #1 ($array) must be of type array, null given
152
153-- Iteration 26 --array_diff(): Argument #1 ($array) must be of type array, resource given
154Done
155