]> granicus.if.org Git - php/commitdiff
Disable restrictions regarding arrays in constants at run-time.
authorBob Weinand <bobwei9@hotmail.com>
Wed, 30 Jul 2014 15:57:07 +0000 (17:57 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Wed, 30 Jul 2014 15:57:07 +0000 (17:57 +0200)
For the discussion around it, see the thread on the mailing list:
http://www.mail-archive.com/internals@lists.php.net/msg68245.html

NEWS
Zend/tests/constant_expressions_arrays.phpt
Zend/tests/errmsg_040.phpt
Zend/tests/ns_059.phpt
Zend/zend_language_parser.y
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/standard/array.c

diff --git a/NEWS b/NEWS
index ba5882767bae69d6e347581814daac23fb063fda..7516f0cf107a77b237a3833d961f7c3121a3e41b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP                                                                        NEWS
 
 - Core:
   . Fixed bug #67693 (incorrect push to the empty array). (Tjerk)
+  . Removed inconsistency regarding behaviour of array in constants at
+    run-time. (Bob)
 
  - SPL:
   . Revert fix for bug #67064 (BC issues). (Bob)
index 061fcc6a928b367ea15a949045606482eaefab0d..2ab03453de6b810e71976d598ad405444352c4dd 100644 (file)
@@ -22,7 +22,7 @@ class foo {
 
 var_dump(foo::bar);
 
-var_dump(a); // Eventually allow that later with array dereferencing of constants
+var_dump(a, a[0], a[2], a[2][1], a[3]);
 
 ?>
 --EXPECTF--
@@ -32,4 +32,35 @@ int(1)
 int(4)
 int(1)
 
-Fatal error: Arrays are not allowed in constants at run-time in %s on line %d
+Notice: Undefined offset: 3 in %s on line %d
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    array(1) {
+      [0]=>
+      int(4)
+    }
+  }
+}
+int(1)
+array(2) {
+  [0]=>
+  int(3)
+  [1]=>
+  array(1) {
+    [0]=>
+    int(4)
+  }
+}
+array(1) {
+  [0]=>
+  int(4)
+}
+NULL
index c3a007f8c174edae677f8e5458b185cecc4a95d5..cda8d4c76af0c8580dd25653459a28ae973b649f 100644 (file)
@@ -12,4 +12,12 @@ var_dump(test::TEST);
 echo "Done\n";
 ?>
 --EXPECTF--    
-Fatal error: Arrays are not allowed in constants at run-time in %s on line %d
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+Done
index 48da40b3f64bcf9908e6b08ffaa894f96c861176..701e448812e7765f98c9e37dc5caee3b8c579870 100644 (file)
@@ -7,5 +7,5 @@ const C = array();
 var_dump(C);
 ?>
 --EXPECTF--
-Fatal error: Arrays are not allowed in constants at run-time in %sns_059.php on line 4
-
+array(0) {
+}
index 56e702e8f9f4e34e31ddd046c41d6cfc2c05c7d1..7502723564ed5db67686230ca76d9af655571b1e 100644 (file)
@@ -865,13 +865,16 @@ yield_expr:
 ;
 
 combined_scalar_offset:
-         combined_scalar '[' dim_offset ']' { zend_do_begin_variable_parse(TSRMLS_C); fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
-       | combined_scalar_offset '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
-    | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' { $1.EA = 0; zend_do_begin_variable_parse(TSRMLS_C); fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
+               combined_scalar '[' dim_offset ']' { zend_do_begin_variable_parse(TSRMLS_C); fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
+       |       combined_scalar_offset '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
+       |       T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' { $1.EA = 0; zend_do_begin_variable_parse(TSRMLS_C); fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
+       |       general_constant '[' dim_offset ']' { zend_do_begin_variable_parse(TSRMLS_C); fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
+;
 
 combined_scalar:
-      T_ARRAY '(' array_pair_list ')' { $$ = $3; }
-    | '[' array_pair_list ']' { $$ = $2; }
+               T_ARRAY '(' array_pair_list ')' { $$ = $3; }
+       |       '[' array_pair_list ']' { $$ = $2; }
+;
 
 function:
        T_FUNCTION { $$.u.op.opline_num = CG(zend_lineno); }
@@ -1038,20 +1041,22 @@ static_operation:
        |       '(' static_scalar_value ')' { $$ = $2; }
 ;
 
-
-scalar:
-               T_STRING_VARNAME                { $$ = $1; }
-       |       class_name_scalar       { $$ = $1; }
-       |       class_constant          { $$ = $1; }
+general_constant:
+               class_constant { $$ = $1; }
        |       namespace_name  { zend_do_fetch_constant(&$$, NULL, &$1, ZEND_RT, 1 TSRMLS_CC); }
        |       T_NAMESPACE T_NS_SEPARATOR namespace_name { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant);  zend_do_build_namespace_name(&$$, &$$, &$3 TSRMLS_CC); $3 = $$; zend_do_fetch_constant(&$$, NULL, &$3, ZEND_RT, 0 TSRMLS_CC); }
        |       T_NS_SEPARATOR namespace_name { char *tmp = estrndup(Z_STRVAL($2.u.constant), Z_STRLEN($2.u.constant)+1); memcpy(&(tmp[1]), Z_STRVAL($2.u.constant), Z_STRLEN($2.u.constant)+1); tmp[0] = '\\'; efree(Z_STRVAL($2.u.constant)); Z_STRVAL($2.u.constant) = tmp; ++Z_STRLEN($2.u.constant); zend_do_fetch_constant(&$$, NULL, &$2, ZEND_RT, 0 TSRMLS_CC); }
-       |       common_scalar                   { $$ = $1; }
-       |       '"' encaps_list '"'     { $$ = $2; }
-       |       T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
-       |       T_CLASS_C                               { if (Z_TYPE($1.u.constant) == IS_CONSTANT) {zend_do_fetch_constant(&$$, NULL, &$1, ZEND_RT, 1 TSRMLS_CC);} else {$$ = $1;} }
 ;
 
+scalar:
+               T_STRING_VARNAME { $$ = $1; }
+       |       general_constant { $$ = $1; }
+       |       class_name_scalar { $$ = $1; }
+       |       common_scalar { $$ = $1; }
+       |       '"' encaps_list '"' { $$ = $2; }
+       |       T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
+       |       T_CLASS_C { if (Z_TYPE($1.u.constant) == IS_CONSTANT) {zend_do_fetch_constant(&$$, NULL, &$1, ZEND_RT, 1 TSRMLS_CC);} else {$$ = $1;} }
+;
 
 static_array_pair_list:
                /* empty */ { $$.op_type = IS_CONST; INIT_PZVAL(&$$.u.constant); array_init(&$$.u.constant); $$.u.ast = zend_ast_create_constant(&$$.u.constant); }
index cadaaa757970f9fe10bb2e6215bf53e74e7d38e0..705e46e7d338ea9891a2a520fa584047997c362e 100644 (file)
@@ -3772,9 +3772,6 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|CONST|UNUSED, CONST)
                }
        }
 constant_fetch_end:
-       if (Z_TYPE(EX_T(opline->result.var).tmp_var) == IS_ARRAY) {
-               zend_error_noreturn(E_ERROR, "Arrays are not allowed in constants at run-time");
-       }
        CHECK_EXCEPTION();
        ZEND_VM_NEXT_OPCODE();
 }
index c085276a33241101dc45b66805f977d7964be9ff..993aaee7474e5a61a5700fa3541d0f2821bd8227 100644 (file)
@@ -4036,9 +4036,6 @@ static int ZEND_FASTCALL  ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCO
                }
        }
 constant_fetch_end:
-       if (Z_TYPE(EX_T(opline->result.var).tmp_var) == IS_ARRAY) {
-               zend_error_noreturn(E_ERROR, "Arrays are not allowed in constants at run-time");
-       }
        CHECK_EXCEPTION();
        ZEND_VM_NEXT_OPCODE();
 }
@@ -16001,9 +15998,6 @@ static int ZEND_FASTCALL  ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE
                }
        }
 constant_fetch_end:
-       if (Z_TYPE(EX_T(opline->result.var).tmp_var) == IS_ARRAY) {
-               zend_error_noreturn(E_ERROR, "Arrays are not allowed in constants at run-time");
-       }
        CHECK_EXCEPTION();
        ZEND_VM_NEXT_OPCODE();
 }
@@ -25613,9 +25607,6 @@ static int ZEND_FASTCALL  ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPC
                }
        }
 constant_fetch_end:
-       if (Z_TYPE(EX_T(opline->result.var).tmp_var) == IS_ARRAY) {
-               zend_error_noreturn(E_ERROR, "Arrays are not allowed in constants at run-time");
-       }
        CHECK_EXCEPTION();
        ZEND_VM_NEXT_OPCODE();
 }
index cca2f2583cdacfbf2818f71ad85e65e1c9201e60..f4806593c10d8a801e0c6ad0c8e5db8df04c39d7 100644 (file)
@@ -339,7 +339,6 @@ PHP_FUNCTION(count)
                                        RETVAL_LONG(Z_LVAL_P(retval));
                                        zval_ptr_dtor(&retval);
                                }
-                               zval_ptr_dtor(&mode_zv);
                                return;
                        }
 #endif