com php-src: Disable restrictions regarding arrays in constants at run-time. 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
| From: | Bob Weinand | Date: | Wed, 30 Jul 2014 15:57:07 +0000 |
| Subject: | com php-src: Disable restrictions regarding arrays in constants at run-time. 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 |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79673@lists.php.net to get a copy of this message | ||
Commit: d5ddd2dbb263cd626a5e0f203c00d6f39168507b
Author: Bob Weinand <bobwei9@hotmail.com> Wed, 30 Jul 2014 17:57:07 +0200
Parents: 354ee12b73dbe20d0c4fa7883eb34714f89109df
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d5ddd2dbb263cd626a5e0f203c00d6f39168507b
Log:
Disable restrictions regarding arrays in constants at run-time.
For the discussion around it, see the thread on the mailing list:
http://www.mail-archive.com/internals@lists.php.net/msg68245.html
Changed paths:
M NEWS
M Zend/tests/constant_expressions_arrays.phpt
M Zend/tests/errmsg_040.phpt
M Zend/tests/ns_059.phpt
M Zend/zend_language_parser.y
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
M ext/standard/array.c
Diff:
diff --git a/NEWS b/NEWS
index ba58827..7516f0c 100644
--- 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)
diff --git a/Zend/tests/constant_expressions_arrays.phpt
b/Zend/tests/constant_expressions_arrays.phpt
index 061fcc6..2ab0345 100644
--- a/Zend/tests/constant_expressions_arrays.phpt
+++ b/Zend/tests/constant_expressions_arrays.phpt
@@ -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
diff --git a/Zend/tests/errmsg_040.phpt b/Zend/tests/errmsg_040.phpt
index c3a007f..cda8d4c 100644
--- a/Zend/tests/errmsg_040.phpt
+++ b/Zend/tests/errmsg_040.phpt
@@ -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
diff --git a/Zend/tests/ns_059.phpt b/Zend/tests/ns_059.phpt
index 48da40b..701e448 100644
--- a/Zend/tests/ns_059.phpt
+++ b/Zend/tests/ns_059.phpt
@@ -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) {
+}
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 56e702e..7502723 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -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); }
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index cadaaa7..705e46e 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -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();
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index c085276..993aaee 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -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();
}
diff --git a/ext/standard/array.c b/ext/standard/array.c
index cca2f25..f480659 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -339,7 +339,6 @@ PHP_FUNCTION(count)
RETVAL_LONG(Z_LVAL_P(retval));
zval_ptr_dtor(&retval);
}
- zval_ptr_dtor(&mode_zv);
return;
}
#endif