1--TEST--
2Test array_diff() function : usage variations - arrays containing referenced variables
3--FILE--
4<?php
5/*
6 * Test how array_diff compares arrays that
7 * 1. Contain referenced variables
8 * 2. Have been referenced to each other
9 */
10
11echo "*** Testing array_diff() : usage variations ***\n";
12$a = 'a';
13
14$arr1 = array ("&$a", 'b', 'c');
15$arr2 = array (1, 2, 3);
16echo "-- Basic Comparison --\n";
17var_dump(array_diff($arr1, $arr2));
18var_dump(array_diff($arr2, $arr1));
19
20$a = 1;
21
22echo "-- \$a changed --\n";
23var_dump(array_diff($arr1, $arr2));
24var_dump(array_diff($arr2, $arr1));
25
26
27$arr2 = &$arr1;
28echo "-- Arrays referenced to each other --\n";
29var_dump(array_diff($arr1, $arr2));
30var_dump(array_diff($arr2, $arr1));
31
32
33$arr1 = array('x', 'y', 'z');
34echo "-- \$arr1 changed --\n";
35var_dump(array_diff($arr1, $arr2));
36var_dump(array_diff($arr2, $arr1));
37
38
39echo "Done";
40?>
41--EXPECT--
42*** Testing array_diff() : usage variations ***
43-- Basic Comparison --
44array(3) {
45  [0]=>
46  string(2) "&a"
47  [1]=>
48  string(1) "b"
49  [2]=>
50  string(1) "c"
51}
52array(3) {
53  [0]=>
54  int(1)
55  [1]=>
56  int(2)
57  [2]=>
58  int(3)
59}
60-- $a changed --
61array(3) {
62  [0]=>
63  string(2) "&a"
64  [1]=>
65  string(1) "b"
66  [2]=>
67  string(1) "c"
68}
69array(3) {
70  [0]=>
71  int(1)
72  [1]=>
73  int(2)
74  [2]=>
75  int(3)
76}
77-- Arrays referenced to each other --
78array(0) {
79}
80array(0) {
81}
82-- $arr1 changed --
83array(0) {
84}
85array(0) {
86}
87Done
88