1--TEST--
2Test of the *intersect* bunch of functions (both assoc and non-assoc)
3--FILE--
4<?php
5error_reporting(E_ALL);
6class cr {
7    private $priv_member;
8    public  $public_member;
9    function __construct($val) {
10        $this->priv_member = $val;
11        $this->public_member = $val;
12    }
13    static function comp_func_cr($a, $b) {
14        if ($a->priv_member === $b->priv_member) return 0;
15        return ($a->priv_member > $b->priv_member)? 1:-1;
16    }
17}
18
19function comp_func($a, $b) {
20    if ($a === $b) return 0;
21    return ($a > $b)? 1:-1;
22
23}
24
25function comp_func_cr($a, $b) {
26    if ($a->public_member === $b->public_member) return 0;
27    return ($a->public_member > $b->public_member)? 1:-1;
28}
29
30$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),);
31$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),);
32
33/* array_uintersect() */
34echo "begin ------------ array_uintersect() ---------------------------\n";
35echo '$a='.var_export($a,TRUE).";\n";
36echo '$b='.var_export($b,TRUE).";\n";
37echo 'var_dump(array_uintersect($a, $b, "comp_func_cr"));'."\n";
38var_dump(array_uintersect($a, $b, "comp_func_cr"));
39echo "end   ------------ array_uintersect() ---------------------------\n";
40
41/* array_uintersect_assoc() */
42echo "begin ------------ array_uintersect_assoc() ---------------------\n";
43echo '$a='.var_export($a,TRUE).";\n";
44echo '$b='.var_export($b,TRUE).";\n";
45echo 'var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));'."\n";
46var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));
47echo "end   ------------ array_uintersect_assoc() ---------------------\n";
48
49/* array_uintersect_uassoc() - with ordinary function */
50echo "begin ------------ array_uintersect_uassoc() with ordinary func -\n";
51echo '$a='.var_export($a,TRUE).";\n";
52echo '$b='.var_export($b,TRUE).";\n";
53echo 'var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));'."\n";
54var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));
55echo "end   ------------ array_uintersect_uassoc() with ordinary func -\n";
56
57/* array_uintersect_uassoc() - by method call */
58echo "begin ------------ array_uintersect_uassoc() with method --------\n";
59echo '$a='.var_export($a,TRUE).";\n";
60echo '$b='.var_export($b,TRUE).";\n";
61echo 'var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));'."\n";
62var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));
63echo "end   ------------ array_uintersect_uassoc() with method --------\n";
64?>
65--EXPECTF--
66begin ------------ array_uintersect() ---------------------------
67$a=array (
68  '0.1' =>
69  \cr::__set_state(array(
70     'priv_member' => 9,
71     'public_member' => 9,
72  )),
73  '0.5' =>
74  \cr::__set_state(array(
75     'priv_member' => 12,
76     'public_member' => 12,
77  )),
78  0 =>
79  \cr::__set_state(array(
80     'priv_member' => 23,
81     'public_member' => 23,
82  )),
83  1 =>
84  \cr::__set_state(array(
85     'priv_member' => 4,
86     'public_member' => 4,
87  )),
88  2 =>
89  \cr::__set_state(array(
90     'priv_member' => -15,
91     'public_member' => -15,
92  )),
93);
94$b=array (
95  '0.2' =>
96  \cr::__set_state(array(
97     'priv_member' => 9,
98     'public_member' => 9,
99  )),
100  '0.5' =>
101  \cr::__set_state(array(
102     'priv_member' => 22,
103     'public_member' => 22,
104  )),
105  0 =>
106  \cr::__set_state(array(
107     'priv_member' => 3,
108     'public_member' => 3,
109  )),
110  1 =>
111  \cr::__set_state(array(
112     'priv_member' => 4,
113     'public_member' => 4,
114  )),
115  2 =>
116  \cr::__set_state(array(
117     'priv_member' => -15,
118     'public_member' => -15,
119  )),
120);
121var_dump(array_uintersect($a, $b, "comp_func_cr"));
122array(3) {
123  ["0.1"]=>
124  object(cr)#%d (2) {
125    ["priv_member":"cr":private]=>
126    int(9)
127    ["public_member"]=>
128    int(9)
129  }
130  [1]=>
131  object(cr)#%d (2) {
132    ["priv_member":"cr":private]=>
133    int(4)
134    ["public_member"]=>
135    int(4)
136  }
137  [2]=>
138  object(cr)#%d (2) {
139    ["priv_member":"cr":private]=>
140    int(-15)
141    ["public_member"]=>
142    int(-15)
143  }
144}
145end   ------------ array_uintersect() ---------------------------
146begin ------------ array_uintersect_assoc() ---------------------
147$a=array (
148  '0.1' =>
149  \cr::__set_state(array(
150     'priv_member' => 9,
151     'public_member' => 9,
152  )),
153  '0.5' =>
154  \cr::__set_state(array(
155     'priv_member' => 12,
156     'public_member' => 12,
157  )),
158  0 =>
159  \cr::__set_state(array(
160     'priv_member' => 23,
161     'public_member' => 23,
162  )),
163  1 =>
164  \cr::__set_state(array(
165     'priv_member' => 4,
166     'public_member' => 4,
167  )),
168  2 =>
169  \cr::__set_state(array(
170     'priv_member' => -15,
171     'public_member' => -15,
172  )),
173);
174$b=array (
175  '0.2' =>
176  \cr::__set_state(array(
177     'priv_member' => 9,
178     'public_member' => 9,
179  )),
180  '0.5' =>
181  \cr::__set_state(array(
182     'priv_member' => 22,
183     'public_member' => 22,
184  )),
185  0 =>
186  \cr::__set_state(array(
187     'priv_member' => 3,
188     'public_member' => 3,
189  )),
190  1 =>
191  \cr::__set_state(array(
192     'priv_member' => 4,
193     'public_member' => 4,
194  )),
195  2 =>
196  \cr::__set_state(array(
197     'priv_member' => -15,
198     'public_member' => -15,
199  )),
200);
201var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));
202array(2) {
203  [1]=>
204  object(cr)#%d (2) {
205    ["priv_member":"cr":private]=>
206    int(4)
207    ["public_member"]=>
208    int(4)
209  }
210  [2]=>
211  object(cr)#%d (2) {
212    ["priv_member":"cr":private]=>
213    int(-15)
214    ["public_member"]=>
215    int(-15)
216  }
217}
218end   ------------ array_uintersect_assoc() ---------------------
219begin ------------ array_uintersect_uassoc() with ordinary func -
220$a=array (
221  '0.1' =>
222  \cr::__set_state(array(
223     'priv_member' => 9,
224     'public_member' => 9,
225  )),
226  '0.5' =>
227  \cr::__set_state(array(
228     'priv_member' => 12,
229     'public_member' => 12,
230  )),
231  0 =>
232  \cr::__set_state(array(
233     'priv_member' => 23,
234     'public_member' => 23,
235  )),
236  1 =>
237  \cr::__set_state(array(
238     'priv_member' => 4,
239     'public_member' => 4,
240  )),
241  2 =>
242  \cr::__set_state(array(
243     'priv_member' => -15,
244     'public_member' => -15,
245  )),
246);
247$b=array (
248  '0.2' =>
249  \cr::__set_state(array(
250     'priv_member' => 9,
251     'public_member' => 9,
252  )),
253  '0.5' =>
254  \cr::__set_state(array(
255     'priv_member' => 22,
256     'public_member' => 22,
257  )),
258  0 =>
259  \cr::__set_state(array(
260     'priv_member' => 3,
261     'public_member' => 3,
262  )),
263  1 =>
264  \cr::__set_state(array(
265     'priv_member' => 4,
266     'public_member' => 4,
267  )),
268  2 =>
269  \cr::__set_state(array(
270     'priv_member' => -15,
271     'public_member' => -15,
272  )),
273);
274var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));
275array(2) {
276  [1]=>
277  object(cr)#%d (2) {
278    ["priv_member":"cr":private]=>
279    int(4)
280    ["public_member"]=>
281    int(4)
282  }
283  [2]=>
284  object(cr)#%d (2) {
285    ["priv_member":"cr":private]=>
286    int(-15)
287    ["public_member"]=>
288    int(-15)
289  }
290}
291end   ------------ array_uintersect_uassoc() with ordinary func -
292begin ------------ array_uintersect_uassoc() with method --------
293$a=array (
294  '0.1' =>
295  \cr::__set_state(array(
296     'priv_member' => 9,
297     'public_member' => 9,
298  )),
299  '0.5' =>
300  \cr::__set_state(array(
301     'priv_member' => 12,
302     'public_member' => 12,
303  )),
304  0 =>
305  \cr::__set_state(array(
306     'priv_member' => 23,
307     'public_member' => 23,
308  )),
309  1 =>
310  \cr::__set_state(array(
311     'priv_member' => 4,
312     'public_member' => 4,
313  )),
314  2 =>
315  \cr::__set_state(array(
316     'priv_member' => -15,
317     'public_member' => -15,
318  )),
319);
320$b=array (
321  '0.2' =>
322  \cr::__set_state(array(
323     'priv_member' => 9,
324     'public_member' => 9,
325  )),
326  '0.5' =>
327  \cr::__set_state(array(
328     'priv_member' => 22,
329     'public_member' => 22,
330  )),
331  0 =>
332  \cr::__set_state(array(
333     'priv_member' => 3,
334     'public_member' => 3,
335  )),
336  1 =>
337  \cr::__set_state(array(
338     'priv_member' => 4,
339     'public_member' => 4,
340  )),
341  2 =>
342  \cr::__set_state(array(
343     'priv_member' => -15,
344     'public_member' => -15,
345  )),
346);
347var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));
348array(2) {
349  [1]=>
350  object(cr)#%d (2) {
351    ["priv_member":"cr":private]=>
352    int(4)
353    ["public_member"]=>
354    int(4)
355  }
356  [2]=>
357  object(cr)#%d (2) {
358    ["priv_member":"cr":private]=>
359    int(-15)
360    ["public_member"]=>
361    int(-15)
362  }
363}
364end   ------------ array_uintersect_uassoc() with method --------
365