diff options
| author | Anatol Belski <ab@php.net> | 2014-08-04 10:28:03 +0200 |
|---|---|---|
| committer | Anatol Belski <ab@php.net> | 2014-08-04 10:28:03 +0200 |
| commit | 616275859e2b195e0ea8e90a26a0ed8801a80765 (patch) | |
| tree | 2ff611420601c1edec72c9ea71e3dafd60bc05f6 /Zend | |
| parent | 5cadd9d6d08fa195f90746302b4d18ddebb79a12 (diff) | |
| parent | 38a4b934cac843146843e226470c2ed37033a985 (diff) | |
| download | php-git-616275859e2b195e0ea8e90a26a0ed8801a80765.tar.gz | |
Merge remote-tracking branch 'origin/str_size_and_int64_56_backport' into str_size_and_int64
* origin/str_size_and_int64_56_backport: (51 commits)
backport the fix for bug #67739
fix macro
Fix bug #67705 (extensive backtracking in rule regular expression)
add test
Fix bug #67705 (extensive backtracking in rule regular expression)
Fix wrong lenght size
Bug #51096 - Remove unnecessary ? for first/last day of
Moved streams related functions to xp_ssl.c
Remove duplicate NEWS
Update NEWS
Update NEWS
Update NEWS
BFN
BFN
Fixed bug #67715 (php-milter does not build and crashes randomly).
We need to turn off any strict mode here for this warning to show up
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
Revert "Fix bug #67064 in a BC safe way"
Updated NEWS for #67693
Updated NEWS for #67693
...
Diffstat (limited to 'Zend')
| -rw-r--r-- | Zend/tests/constant_expressions_arrays.phpt | 35 | ||||
| -rw-r--r-- | Zend/tests/constant_expressions_self_referencing_array.phpt | 2 | ||||
| -rw-r--r-- | Zend/tests/errmsg_040.phpt | 10 | ||||
| -rw-r--r-- | Zend/tests/ns_059.phpt | 4 | ||||
| -rw-r--r-- | Zend/zend_ast.c | 17 | ||||
| -rw-r--r-- | Zend/zend_language_parser.y | 33 | ||||
| -rw-r--r-- | Zend/zend_vm_def.h | 14 | ||||
| -rw-r--r-- | Zend/zend_vm_execute.h | 20 |
8 files changed, 96 insertions, 39 deletions
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/constant_expressions_self_referencing_array.phpt b/Zend/tests/constant_expressions_self_referencing_array.phpt index 09f862e048..ae76a08602 100644 --- a/Zend/tests/constant_expressions_self_referencing_array.phpt +++ b/Zend/tests/constant_expressions_self_referencing_array.phpt @@ -1,7 +1,5 @@ --TEST-- Self-referencing constant expression (part of a constant AST) ---XFAIL-- -Not yet fixed, to be fixed for PHP 5.6 --FILE-- <?php class A { 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_ast.c b/Zend/zend_ast.c index 76a1df1f67..1381f16177 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -251,10 +251,19 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s zval_dtor(&op2); break; case ZEND_CONST: - *result = *ast->u.val; - zval_copy_ctor(result); - if (IS_CONSTANT_TYPE(Z_TYPE_P(result))) { - zval_update_constant_ex(&result, 1, scope TSRMLS_CC); + /* class constants may be updated in-place */ + if (scope) { + if (IS_CONSTANT_TYPE(Z_TYPE_P(ast->u.val))) { + zval_update_constant_ex(&ast->u.val, 1, scope TSRMLS_CC); + } + *result = *ast->u.val; + zval_copy_ctor(result); + } else { + *result = *ast->u.val; + zval_copy_ctor(result); + if (IS_CONSTANT_TYPE(Z_TYPE_P(result))) { + zval_update_constant_ex(&result, 1, scope TSRMLS_CC); + } } break; case ZEND_BOOL_AND: diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 8887bac3cd..de2e3309dd 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_STRSIZE($2.u.constant)+1); memcpy(&(tmp[1]), Z_STRVAL($2.u.constant), Z_STRSIZE($2.u.constant)+1); tmp[0] = '\\'; efree(Z_STRVAL($2.u.constant)); Z_STRVAL($2.u.constant) = tmp; ++Z_STRSIZE($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 7e9cfc3215..e0a716dbb8 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(); } @@ -5387,7 +5384,16 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST) c.value = *tmp_ptr; } else { INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); + if (Z_TYPE(c.value) == IS_ARRAY) { + HashTable *ht; + + ALLOC_HASHTABLE(ht); + zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL(c.value)), NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(ht, Z_ARRVAL(c.value), (copy_ctor_func_t) zval_deep_copy, NULL, sizeof(zval *)); + Z_ARRVAL(c.value) = ht; + } else { + zval_copy_ctor(&c.value); + } } c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRSIZE_P(name)); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index ce1efa8805..d2fc1bf089 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(); } @@ -4323,7 +4320,16 @@ static int ZEND_FASTCALL ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER(ZEND_OPCOD c.value = *tmp_ptr; } else { INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); + if (Z_TYPE(c.value) == IS_ARRAY) { + HashTable *ht; + + ALLOC_HASHTABLE(ht); + zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL(c.value)), NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(ht, Z_ARRVAL(c.value), (copy_ctor_func_t) zval_deep_copy, NULL, sizeof(zval *)); + Z_ARRVAL(c.value) = ht; + } else { + zval_copy_ctor(&c.value); + } } c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRSIZE_P(name)); @@ -15992,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(); } @@ -25604,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(); } |
