Skip to content

Commit 1836daf

Browse files
committed
Fixed bug #43318
The "const" statement is still allowed outside of namespaces but arrays are disabled.
1 parent a6fbf1b commit 1836daf

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

Zend/tests/ns_039.phpt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
039: Constant declaration
33
--FILE--
44
<?php
5+
function foo($a = A) {
6+
echo "$a\n";
7+
}
8+
function bar($a = array(A => B)) {
9+
foreach ($a as $key => $val) {
10+
echo "$key\n";
11+
echo "$val\n";
12+
}
13+
}
514
const A = "ok";
615
const B = A;
7-
const C = array("ok");
8-
const D = array(B);
916
echo A . "\n";
1017
echo B . "\n";
11-
print_r(C);
12-
print_r(D);
18+
foo();
19+
bar();
1320
--EXPECT--
1421
ok
1522
ok
16-
Array
17-
(
18-
[0] => ok
19-
)
20-
Array
21-
(
22-
[0] => ok
23-
)
23+
ok
24+
ok
25+
ok

Zend/tests/ns_040.phpt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ namespace X;
66
use X as Y;
77
const A = "ok\n";
88
const B = A;
9-
const C = array(A);
10-
const D = array("aaa"=>A);
11-
const E = array(A=>"aaa\n");
129
function f1($x=A) {
1310
echo $x;
1411
}
@@ -42,9 +39,6 @@ f2();
4239
f3();
4340
f4();
4441
echo B;
45-
$x = C; echo $x[0];
46-
$x = D; echo $x["aaa"];
47-
$x = E; echo $x["ok\n"];
4842
f5();
4943
f6();
5044
f7();
@@ -61,8 +55,5 @@ ok
6155
ok
6256
ok
6357
ok
64-
aaa
65-
ok
66-
ok
6758
ok
6859
aaa

Zend/tests/ns_059.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
059: Constant arrays
3+
--FILE--
4+
<?php
5+
const C = array();
6+
--EXPECTF--
7+
Fatal error: Arrays are not allowed as constants in %sns_059.php on line 2
8+

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,6 +4820,10 @@ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
48204820
{
48214821
zend_op *opline;
48224822

4823+
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
4824+
zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
4825+
}
4826+
48234827
if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) {
48244828
zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant));
48254829
}

0 commit comments

Comments
 (0)