]> granicus.if.org Git - php/commitdiff
Fixed bug #43318
authorDmitry Stogov <dmitry@php.net>
Thu, 22 Nov 2007 10:46:26 +0000 (10:46 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 22 Nov 2007 10:46:26 +0000 (10:46 +0000)
The "const" statement is still allowed outside of namespaces but arrays are disabled.

Zend/tests/ns_039.phpt
Zend/tests/ns_040.phpt
Zend/tests/ns_059.phpt [new file with mode: 0755]
Zend/zend_compile.c

index 95fae8fc01e013a667359f59388ccf5c1e03523b..c5e79e48c5493b60f9c7a5c119a18a5346a1ea1d 100644 (file)
@@ -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
index f017aff0bd5fc47fa4b1b2bfd3018e2df3bf71a3..fb2314466c4b18f80c39c39cd621d9bdc8b000ef 100644 (file)
@@ -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
diff --git a/Zend/tests/ns_059.phpt b/Zend/tests/ns_059.phpt
new file mode 100755 (executable)
index 0000000..ea66037
--- /dev/null
@@ -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
+
index 84e1181e8c6432501dc90e2e789fe69806ff4ba7..5da1f7886221e1c14b33249befb48b50227ea9fd 100644 (file)
@@ -4820,6 +4820,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 '%s'", Z_STRVAL(name->u.constant));
        }