mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
Fixed bug #43318
The "const" statement is still allowed outside of namespaces but arrays are disabled.
This commit is contained in:
parent
1e9fec2a49
commit
975a66da79
@ -2,22 +2,24 @@
|
||||
039: Constant declaration
|
||||
--FILE--
|
||||
<?php
|
||||
function foo($a = A) {
|
||||
echo "$a\n";
|
||||
}
|
||||
function bar($a = array(A => B)) {
|
||||
foreach ($a as $key => $val) {
|
||||
echo "$key\n";
|
||||
echo "$val\n";
|
||||
}
|
||||
}
|
||||
const A = "ok";
|
||||
const B = A;
|
||||
const C = array("ok");
|
||||
const D = array(B);
|
||||
echo A . "\n";
|
||||
echo B . "\n";
|
||||
print_r(C);
|
||||
print_r(D);
|
||||
foo();
|
||||
bar();
|
||||
--EXPECT--
|
||||
ok
|
||||
ok
|
||||
Array
|
||||
(
|
||||
[0] => ok
|
||||
)
|
||||
Array
|
||||
(
|
||||
[0] => ok
|
||||
)
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
|
@ -6,9 +6,6 @@ namespace X;
|
||||
use X as Y;
|
||||
const A = "ok\n";
|
||||
const B = A;
|
||||
const C = array(A);
|
||||
const D = array("aaa"=>A);
|
||||
const E = array(A=>"aaa\n");
|
||||
function f1($x=A) {
|
||||
echo $x;
|
||||
}
|
||||
@ -42,9 +39,6 @@ f2();
|
||||
f3();
|
||||
f4();
|
||||
echo B;
|
||||
$x = C; echo $x[0];
|
||||
$x = D; echo $x["aaa"];
|
||||
$x = E; echo $x["ok\n"];
|
||||
f5();
|
||||
f6();
|
||||
f7();
|
||||
@ -61,8 +55,5 @@ ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
aaa
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
aaa
|
||||
|
8
Zend/tests/ns_059.phpt
Executable file
8
Zend/tests/ns_059.phpt
Executable file
@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
059: Constant arrays
|
||||
--FILE--
|
||||
<?php
|
||||
const C = array();
|
||||
--EXPECTF--
|
||||
Fatal error: Arrays are not allowed as constants in %sns_059.php on line 2
|
||||
|
@ -5338,6 +5338,10 @@ void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
zend_op *opline;
|
||||
|
||||
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
|
||||
zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
|
||||
}
|
||||
|
||||
if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) {
|
||||
zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%R'", Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user