xref: /PHP-7.2/ext/standard/tests/array/bug25708.phpt (revision c55c7ef0)
1--TEST--
2Bug #25708 (extract($GLOBALS, EXTR_REFS) mangles $GLOBALS)
3--FILE--
4<?php
5function foo($ref, $alt) {
6	unset($GLOBALS['a']);
7	unset($GLOBALS['b']);
8	$GLOBALS['a'] = 1;
9	$GLOBALS['b'] = 2;
10
11	$org_a = $GLOBALS['a'];
12	$org_b = $GLOBALS['b'];
13
14	if ($ref) {
15		global $a, $b;
16	} else {
17		/* zval temp_var(NULL); // refcount = 1
18		 * a = temp_var[x] // refcount = 2
19		 */
20		$a = NULL;
21		$b = NULL;
22	}
23
24	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
25	echo "--\n";
26	if ($alt) {
27		$a = &$GLOBALS['a'];
28		$b = &$GLOBALS['b'];
29	} else {
30		extract($GLOBALS, EXTR_REFS);
31	}
32	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
33	echo "--\n";
34	$a = &$GLOBALS['a'];
35	$b = &$GLOBALS['b'];
36	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
37	echo "--\n";
38	$GLOBALS['b'] = 3;
39	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
40	echo "--\n";
41	$a = 4;
42	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']);
43	echo "--\n";
44	$c = $b;
45	debug_zval_dump($b, $GLOBALS['b'], $c);
46	echo "--\n";
47	$b = 'x';
48	debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b'], $c);
49	echo "--\n";
50	debug_zval_dump($org_a, $org_b);
51	echo "----";
52	if ($ref) echo 'r';
53	if ($alt) echo 'a';
54	echo "\n";
55}
56
57$a = 'ok';
58$b = 'ok';
59$_a = $a;
60$_b = $b;
61
62foo(false, true);
63foo(true, true);
64foo(false, false);
65foo(true, false);
66
67debug_zval_dump($_a, $_b);
68?>
69--EXPECTF--
70NULL
71NULL
72int(1)
73int(2)
74--
75int(1)
76int(2)
77int(1)
78int(2)
79--
80int(1)
81int(2)
82int(1)
83int(2)
84--
85int(1)
86int(3)
87int(1)
88int(3)
89--
90int(4)
91int(3)
92int(4)
93int(3)
94--
95int(3)
96int(3)
97int(3)
98--
99int(4)
100string(1) "x" refcount(%d)
101int(4)
102string(1) "x" refcount(%d)
103int(3)
104--
105int(1)
106int(2)
107----a
108int(1)
109int(2)
110int(1)
111int(2)
112--
113int(1)
114int(2)
115int(1)
116int(2)
117--
118int(1)
119int(2)
120int(1)
121int(2)
122--
123int(1)
124int(3)
125int(1)
126int(3)
127--
128int(4)
129int(3)
130int(4)
131int(3)
132--
133int(3)
134int(3)
135int(3)
136--
137int(4)
138string(1) "x" refcount(%d)
139int(4)
140string(1) "x" refcount(%d)
141int(3)
142--
143int(1)
144int(2)
145----ra
146NULL
147NULL
148int(1)
149int(2)
150--
151int(1)
152int(2)
153int(1)
154int(2)
155--
156int(1)
157int(2)
158int(1)
159int(2)
160--
161int(1)
162int(3)
163int(1)
164int(3)
165--
166int(4)
167int(3)
168int(4)
169int(3)
170--
171int(3)
172int(3)
173int(3)
174--
175int(4)
176string(1) "x" refcount(%d)
177int(4)
178string(1) "x" refcount(%d)
179int(3)
180--
181int(1)
182int(2)
183----
184int(1)
185int(2)
186int(1)
187int(2)
188--
189int(1)
190int(2)
191int(1)
192int(2)
193--
194int(1)
195int(2)
196int(1)
197int(2)
198--
199int(1)
200int(3)
201int(1)
202int(3)
203--
204int(4)
205int(3)
206int(4)
207int(3)
208--
209int(3)
210int(3)
211int(3)
212--
213int(4)
214string(1) "x" refcount(%d)
215int(4)
216string(1) "x" refcount(%d)
217int(3)
218--
219int(1)
220int(2)
221----r
222string(2) "ok" refcount(%d)
223string(2) "ok" refcount(%d)
224