summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/bug29493.phpt
blob: 0cfe45910bede56dd789d3a58d3406da1b92d9bb (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--TEST--
Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals)
--FILE--
<?php
function t1()
{
	$a = array('foo' => 'aaa');
	// refcount($a) = 1
	// refcount($a['foo']) = 1
	$b = $a;
	// refcount($a) = 2
	// refcount($a['foo']) = 1
	$b['foo'] = 'bbb';
	// refcount($a) = 1
	// refcount($a['foo']) = 1

	var_dump($a, $b);

	extract($a, EXTR_REFS);

	$foo = 'noo';

	var_dump($a, $b);
}

function t2()
{
	$a = array('foo' => 'aaa');
	// refcount($a) = 1
	// refcount($a['foo']) = 1
	$b = &$a;
	// refcount($a) = 2
	// is_ref($a) = true
	// refcount($a['foo']) = 1
	$b['foo'] = 'bbb';
	// refcount($a) = 2
	// refcount($a['foo']) = 1

	var_dump($a, $b);

	extract($a, EXTR_REFS);

	$foo = 'noo';

	var_dump($a, $b);
}

function t3()
{
	$a = array('foo' => 'aaa');
	// refcount($a) = 1
	// refcount($a['foo']) = 1
	$b = &$a;
	// refcount($a) = 2
	// is_ref($a) = true
	// refcount($a['foo']) = 1
	unset($b);
	// refcount($a) = 1
	// is_ref($a) = true
	// refcount($a['foo']) = 1

	var_dump($a);

	extract($a, EXTR_REFS);

	$foo = 'noo';

	var_dump($a);
}

t1();
t2();
t3();
?>
--EXPECT--
array(1) {
  ["foo"]=>
  string(3) "aaa"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  string(3) "aaa"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}