The "const" statement is still allowed outside of namespaces but arrays are disabled.
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
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;
}
f3();
f4();
echo B;
-$x = C; echo $x[0];
-$x = D; echo $x["aaa"];
-$x = E; echo $x["ok\n"];
f5();
f6();
f7();
ok
ok
ok
-aaa
-ok
-ok
ok
aaa
--- /dev/null
+--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
+
{
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 '%s'", Z_STRVAL(name->u.constant));
}