xref: /PHP-8.4/Zend/tests/bug42819.phpt (revision d30cd7d7)
1--TEST--
2Bug #42819 (namespaces in indexes of constant arrays)
3--FILE--
4<?php
5namespace foo\foo;
6
7const C = "foo\\foo\\C\n";
8const I = 12;
9
10class foo {
11const I = 32;
12const C = "foo\\foo\\foo::C\n";
13}
14
15namespace foo;
16use \ArrayObject;
17
18const C = "foo\\C\n";
19const I = 11;
20
21class foo {
22    const C = "foo\\foo::C\n";
23    const I = 22;
24    const C1 = C;
25    const C2 = foo\C;
26    const C3 = foo\foo::C;
27    const C4 = \foo\C;
28    const C5 = \foo\foo::C;
29    const C6 = ArrayObject::STD_PROP_LIST;
30    const C7 = E_ERROR;
31}
32
33class bar1 {
34    static $a1 = array(I => 0);
35    static $a2 = array(foo\I => 0);
36    static $a3 = array(foo\foo::I => 0);
37    static $a4 = array(\foo\I => 0);
38    static $a5 = array(\foo\foo::I => 0);
39    static $a6 = array(ArrayObject::STD_PROP_LIST => 0);
40    static $a7 = array(E_ERROR => 0);
41}
42
43class bar2 {
44    static $a1 = array(I => I);
45    static $a2 = array(foo\I => I);
46    static $a3 = array(foo\foo::I => I);
47    static $a4 = array(\foo\I => I);
48    static $a5 = array(\foo\foo::I => I);
49    static $a6 = array(ArrayObject::STD_PROP_LIST => I);
50    static $a7 = array(E_ERROR => I);
51}
52
53class bar3 {
54    static $a1 = array(I => foo\I);
55    static $a2 = array(foo\I => foo\I);
56    static $a3 = array(foo\foo::I => foo\I);
57    static $a4 = array(\foo\I => foo\I);
58    static $a5 = array(\foo\foo::I => foo\I);
59    static $a6 = array(ArrayObject::STD_PROP_LIST => foo\I);
60    static $a7 = array(E_ERROR => foo\I);
61}
62
63class bar4 {
64    static $a1 = array(I => ArrayObject::STD_PROP_LIST);
65    static $a2 = array(foo\I => ArrayObject::STD_PROP_LIST);
66    static $a3 = array(foo\foo::I => ArrayObject::STD_PROP_LIST);
67    static $a4 = array(\foo\I => ArrayObject::STD_PROP_LIST);
68    static $a5 = array(\foo\foo::I => ArrayObject::STD_PROP_LIST);
69    static $a6 = array(ArrayObject::STD_PROP_LIST => ArrayObject::STD_PROP_LIST);
70    static $a7 = array(E_ERROR => ArrayObject::STD_PROP_LIST);
71}
72
73class bar5 {
74    static $a1 = array(I => E_ERROR);
75    static $a2 = array(foo\I => E_ERROR);
76    static $a3 = array(foo\foo::I => E_ERROR);
77    static $a4 = array(\foo\I => E_ERROR);
78    static $a5 = array(\foo\foo::I => E_ERROR);
79    static $a6 = array(ArrayObject::STD_PROP_LIST => E_ERROR);
80    static $a7 = array(E_ERROR => E_ERROR);
81}
82
83echo "first\n";
84echo C;
85echo foo\C;
86echo foo\foo::C;
87echo foo::C;
88echo \foo\foo::C;
89echo ArrayObject::STD_PROP_LIST . "\n";
90echo E_ERROR . "\n";
91echo "second\n";
92echo \foo\foo::C1;
93echo \foo\foo::C2;
94echo \foo\foo::C3;
95echo \foo\foo::C4;
96echo \foo\foo::C5;
97echo \foo\foo::C6 . "\n";
98echo \foo\foo::C7 . "\n";
99
100print_r(bar1::$a1);
101print_r(bar1::$a2);
102print_r(bar1::$a3);
103print_r(bar1::$a4);
104print_r(bar1::$a5);
105print_r(bar1::$a6);
106print_r(bar1::$a7);
107
108print_r(bar2::$a1);
109print_r(bar2::$a2);
110print_r(bar2::$a3);
111print_r(bar2::$a4);
112print_r(bar2::$a5);
113print_r(bar2::$a6);
114print_r(bar2::$a7);
115
116print_r(bar3::$a1);
117print_r(bar3::$a2);
118print_r(bar3::$a3);
119print_r(bar3::$a4);
120print_r(bar3::$a5);
121print_r(bar3::$a6);
122print_r(bar3::$a7);
123
124print_r(bar4::$a1);
125print_r(bar4::$a2);
126print_r(bar4::$a3);
127print_r(bar4::$a4);
128print_r(bar4::$a5);
129print_r(bar4::$a6);
130print_r(bar4::$a7);
131
132print_r(bar5::$a1);
133print_r(bar5::$a2);
134print_r(bar5::$a3);
135print_r(bar5::$a4);
136print_r(bar5::$a5);
137print_r(bar5::$a6);
138print_r(bar5::$a7);
139function oops($a = array(foo\unknown)){}
140oops();
141?>
142--EXPECTF--
143first
144foo\C
145foo\foo\C
146foo\foo\foo::C
147foo\foo::C
148foo\foo::C
1491
1501
151second
152foo\C
153foo\foo\C
154foo\foo\foo::C
155foo\C
156foo\foo::C
1571
1581
159Array
160(
161    [11] => 0
162)
163Array
164(
165    [12] => 0
166)
167Array
168(
169    [32] => 0
170)
171Array
172(
173    [11] => 0
174)
175Array
176(
177    [22] => 0
178)
179Array
180(
181    [1] => 0
182)
183Array
184(
185    [1] => 0
186)
187Array
188(
189    [11] => 11
190)
191Array
192(
193    [12] => 11
194)
195Array
196(
197    [32] => 11
198)
199Array
200(
201    [11] => 11
202)
203Array
204(
205    [22] => 11
206)
207Array
208(
209    [1] => 11
210)
211Array
212(
213    [1] => 11
214)
215Array
216(
217    [11] => 12
218)
219Array
220(
221    [12] => 12
222)
223Array
224(
225    [32] => 12
226)
227Array
228(
229    [11] => 12
230)
231Array
232(
233    [22] => 12
234)
235Array
236(
237    [1] => 12
238)
239Array
240(
241    [1] => 12
242)
243Array
244(
245    [11] => 1
246)
247Array
248(
249    [12] => 1
250)
251Array
252(
253    [32] => 1
254)
255Array
256(
257    [11] => 1
258)
259Array
260(
261    [22] => 1
262)
263Array
264(
265    [1] => 1
266)
267Array
268(
269    [1] => 1
270)
271Array
272(
273    [11] => 1
274)
275Array
276(
277    [12] => 1
278)
279Array
280(
281    [32] => 1
282)
283Array
284(
285    [11] => 1
286)
287Array
288(
289    [22] => 1
290)
291Array
292(
293    [1] => 1
294)
295Array
296(
297    [1] => 1
298)
299
300Fatal error: Uncaught Error: Undefined constant "foo\foo\unknown" in %s:%d
301Stack trace:
302#0 %s(%d): foo\oops()
303#1 {main}
304  thrown in %sbug42819.php on line %d
305