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