xref: /PHP-7.3/ext/standard/tests/array/bug29493.phpt (revision 88ce94a3)
1--TEST--
2Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals)
3--FILE--
4<?php
5function t1()
6{
7	$a = array('foo' => 'aaa');
8	// refcount($a) = 1
9	// refcount($a['foo']) = 1
10	$b = $a;
11	// refcount($a) = 2
12	// refcount($a['foo']) = 1
13	$b['foo'] = 'bbb';
14	// refcount($a) = 1
15	// refcount($a['foo']) = 1
16
17	var_dump($a, $b);
18
19	extract($a, EXTR_REFS);
20
21	$foo = 'noo';
22
23	var_dump($a, $b);
24}
25
26function t2()
27{
28	$a = array('foo' => 'aaa');
29	// refcount($a) = 1
30	// refcount($a['foo']) = 1
31	$b = &$a;
32	// refcount($a) = 2
33	// is_ref($a) = true
34	// refcount($a['foo']) = 1
35	$b['foo'] = 'bbb';
36	// refcount($a) = 2
37	// refcount($a['foo']) = 1
38
39	var_dump($a, $b);
40
41	extract($a, EXTR_REFS);
42
43	$foo = 'noo';
44
45	var_dump($a, $b);
46}
47
48function t3()
49{
50	$a = array('foo' => 'aaa');
51	// refcount($a) = 1
52	// refcount($a['foo']) = 1
53	$b = &$a;
54	// refcount($a) = 2
55	// is_ref($a) = true
56	// refcount($a['foo']) = 1
57	unset($b);
58	// refcount($a) = 1
59	// is_ref($a) = true
60	// refcount($a['foo']) = 1
61
62	var_dump($a);
63
64	extract($a, EXTR_REFS);
65
66	$foo = 'noo';
67
68	var_dump($a);
69}
70
71t1();
72t2();
73t3();
74?>
75--EXPECT--
76array(1) {
77  ["foo"]=>
78  string(3) "aaa"
79}
80array(1) {
81  ["foo"]=>
82  string(3) "bbb"
83}
84array(1) {
85  ["foo"]=>
86  &string(3) "noo"
87}
88array(1) {
89  ["foo"]=>
90  string(3) "bbb"
91}
92array(1) {
93  ["foo"]=>
94  string(3) "bbb"
95}
96array(1) {
97  ["foo"]=>
98  string(3) "bbb"
99}
100array(1) {
101  ["foo"]=>
102  &string(3) "noo"
103}
104array(1) {
105  ["foo"]=>
106  &string(3) "noo"
107}
108array(1) {
109  ["foo"]=>
110  string(3) "aaa"
111}
112array(1) {
113  ["foo"]=>
114  &string(3) "noo"
115}
116