summaryrefslogtreecommitdiff
path: root/Zend/tests/list/list_reference_008.phpt
blob: 2c7898485299227ead4a80a7c71f3bf017cadcbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--TEST--
"Reference Unpacking - Oddities" list()
--FILE--
<?php
$a = 1;
$b =& $a;
$arr = [&$a, &$b];
list(&$a, &$b) = $arr;
var_dump($a, $b, $arr);
$b++;
var_dump($a, $b, $arr);
unset($a, $b, $arr);

/*
 * $a is first set as a reference to the 0'th elem, '1'
 * $a is then set to the value of the 1'st elem, '2'
 * $arr would look like, [2,2]
 * Increment $a, and it should be [3, 2]
 */
$arr = [1, 2];
list(&$a, $a) = $arr;
var_dump($a);
$a++;
var_dump($arr);
unset($a, $arr);

/*
 * We do not allow references to the same variable of rhs.
 */
$a = [1, 2];
$ref =& $a;
list(&$a, &$b) = $a;
var_dump($a, $b);
$a++; $b++;
var_dump($ref);
?>
--EXPECT--
int(1)
int(1)
array(2) {
  [0]=>
  &int(1)
  [1]=>
  &int(1)
}
int(2)
int(2)
array(2) {
  [0]=>
  &int(2)
  [1]=>
  &int(2)
}
int(2)
array(2) {
  [0]=>
  &int(3)
  [1]=>
  int(2)
}
int(1)
int(2)
array(2) {
  [0]=>
  &int(2)
  [1]=>
  &int(3)
}