xref: /PHP-5.4/ext/standard/tests/array/bug25708.phpt (revision 76ae0648)
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--EXPECT--
70NULL refcount(2)
71NULL refcount(2)
72long(1) refcount(3)
73long(2) refcount(3)
74--
75long(1) refcount(1)
76long(2) refcount(1)
77long(1) refcount(1)
78long(2) refcount(1)
79--
80long(1) refcount(1)
81long(2) refcount(1)
82long(1) refcount(1)
83long(2) refcount(1)
84--
85long(1) refcount(1)
86long(3) refcount(1)
87long(1) refcount(1)
88long(3) refcount(1)
89--
90long(4) refcount(1)
91long(3) refcount(1)
92long(4) refcount(1)
93long(3) refcount(1)
94--
95long(3) refcount(1)
96long(3) refcount(1)
97long(3) refcount(2)
98--
99long(4) refcount(1)
100string(1) "x" refcount(1)
101long(4) refcount(1)
102string(1) "x" refcount(1)
103long(3) refcount(2)
104--
105long(1) refcount(2)
106long(2) refcount(2)
107----a
108long(1) refcount(1)
109long(2) refcount(1)
110long(1) refcount(1)
111long(2) refcount(1)
112--
113long(1) refcount(1)
114long(2) refcount(1)
115long(1) refcount(1)
116long(2) refcount(1)
117--
118long(1) refcount(1)
119long(2) refcount(1)
120long(1) refcount(1)
121long(2) refcount(1)
122--
123long(1) refcount(1)
124long(3) refcount(1)
125long(1) refcount(1)
126long(3) refcount(1)
127--
128long(4) refcount(1)
129long(3) refcount(1)
130long(4) refcount(1)
131long(3) refcount(1)
132--
133long(3) refcount(1)
134long(3) refcount(1)
135long(3) refcount(2)
136--
137long(4) refcount(1)
138string(1) "x" refcount(1)
139long(4) refcount(1)
140string(1) "x" refcount(1)
141long(3) refcount(2)
142--
143long(1) refcount(2)
144long(2) refcount(2)
145----ra
146NULL refcount(2)
147NULL refcount(2)
148long(1) refcount(3)
149long(2) refcount(3)
150--
151long(1) refcount(1)
152long(2) refcount(1)
153long(1) refcount(1)
154long(2) refcount(1)
155--
156long(1) refcount(1)
157long(2) refcount(1)
158long(1) refcount(1)
159long(2) refcount(1)
160--
161long(1) refcount(1)
162long(3) refcount(1)
163long(1) refcount(1)
164long(3) refcount(1)
165--
166long(4) refcount(1)
167long(3) refcount(1)
168long(4) refcount(1)
169long(3) refcount(1)
170--
171long(3) refcount(1)
172long(3) refcount(1)
173long(3) refcount(2)
174--
175long(4) refcount(1)
176string(1) "x" refcount(1)
177long(4) refcount(1)
178string(1) "x" refcount(1)
179long(3) refcount(2)
180--
181long(1) refcount(2)
182long(2) refcount(2)
183----
184long(1) refcount(1)
185long(2) refcount(1)
186long(1) refcount(1)
187long(2) refcount(1)
188--
189long(1) refcount(1)
190long(2) refcount(1)
191long(1) refcount(1)
192long(2) refcount(1)
193--
194long(1) refcount(1)
195long(2) refcount(1)
196long(1) refcount(1)
197long(2) refcount(1)
198--
199long(1) refcount(1)
200long(3) refcount(1)
201long(1) refcount(1)
202long(3) refcount(1)
203--
204long(4) refcount(1)
205long(3) refcount(1)
206long(4) refcount(1)
207long(3) refcount(1)
208--
209long(3) refcount(1)
210long(3) refcount(1)
211long(3) refcount(2)
212--
213long(4) refcount(1)
214string(1) "x" refcount(1)
215long(4) refcount(1)
216string(1) "x" refcount(1)
217long(3) refcount(2)
218--
219long(1) refcount(2)
220long(2) refcount(2)
221----r
222string(2) "ok" refcount(2)
223string(2) "ok" refcount(2)
224