summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2014-07-30 17:57:07 +0200
committerBob Weinand <bobwei9@hotmail.com>2014-07-30 17:57:07 +0200
commitd5ddd2dbb263cd626a5e0f203c00d6f39168507b (patch)
tree5e9c7a8f0bbd3b39d990305f56892935a5b4f44e
parent354ee12b73dbe20d0c4fa7883eb34714f89109df (diff)
downloadphp-git-d5ddd2dbb263cd626a5e0f203c00d6f39168507b.tar.gz
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
-rw-r--r--NEWS2
-rw-r--r--Zend/tests/constant_expressions_arrays.phpt35
-rw-r--r--Zend/tests/errmsg_040.phpt10
-rw-r--r--Zend/tests/ns_059.phpt4
-rw-r--r--Zend/zend_language_parser.y33
-rw-r--r--Zend/zend_vm_def.h3
-rw-r--r--Zend/zend_vm_execute.h9
-rw-r--r--ext/standard/array.c1
8 files changed, 65 insertions, 32 deletions
diff --git a/NEWS b/NEWS
index ba5882767b..7516f0cf10 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 061fcc6a92..2ab03453de 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 c3a007f8c1..cda8d4c76a 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 48da40b3f6..701e448812 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 56e702e8f9..7502723564 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 cadaaa7579..705e46e7d3 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 c085276a33..993aaee747 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 cca2f2583c..f4806593c1 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