diff --git a/NEWS b/NEWS index b6ae4b33e5942..4274e637c9436 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed incorrect double to long casting in latest clang. (zeriyoshi) . Added support for defining constants in traits. (sj-i) + . Stop incorrectly emitting false positive deprecation notice alongside + unsupported syntax fatal error for `"{$g{'h'}}"`. (TysonAndre) - Random: . Fixed bug GH-9235 (non-existant $sequence parameter in stub for @@ -73,7 +75,7 @@ PHP NEWS $advance). (Anton Smirnov) . Changed Mt19937 to throw a ValueError instead of InvalidArgumentException for invalid $mode. (timwolla) - . Splitted Random\Randomizer::getInt() (without arguments) to + . Splitted Random\Randomizer::getInt() (without arguments) to Random\Randomizer::nextInt(). (zeriyoshi) - Sockets: diff --git a/Zend/tests/alternative_offset_syntax_in_encaps_string.phpt b/Zend/tests/alternative_offset_syntax_in_encaps_string.phpt new file mode 100644 index 0000000000000..2771b33afa89c --- /dev/null +++ b/Zend/tests/alternative_offset_syntax_in_encaps_string.phpt @@ -0,0 +1,6 @@ +--TEST-- +Alternative offset syntax should emit only E_COMPILE_ERROR in string interpolation +--FILE-- + +--EXPECTF-- +Fatal error: Array and string offset access syntax with curly braces is no longer supported in %s on line 1 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index e52af3339de08..ee983e675cd2c 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -9623,11 +9623,12 @@ static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */ last_const_node.op_type = IS_UNUSED; for (i = 0; i < list->children; i++) { zend_ast *encaps_var = list->child[i]; + if (encaps_var->attr & (ZEND_ENCAPS_VAR_DOLLAR_CURLY|ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR)) { - if (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR) { - zend_error(E_DEPRECATED, "Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead"); - } else { + if ((encaps_var->kind == ZEND_AST_VAR || encaps_var->kind == ZEND_AST_DIM) && (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY)) { zend_error(E_DEPRECATED, "Using ${var} in strings is deprecated, use {$var} instead"); + } else if (encaps_var->kind == ZEND_AST_VAR && (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR)) { + zend_error(E_DEPRECATED, "Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead"); } } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 2802478f29256..afca2917820fa 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -1016,9 +1016,15 @@ ZEND_API zend_string *zend_type_to_string(zend_type type); #define ZEND_ARG_TYPE_IS_TENTATIVE(arg_info) \ ((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_TENTATIVE_BIT) != 0) -#define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce */ +#define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce. Set in zend_compile.c for ZEND_AST_DIM nested within ZEND_AST_COALESCE. */ #define ZEND_DIM_ALTERNATIVE_SYNTAX (1 << 1) /* deprecated curly brace usage */ +/* Attributes for ${} encaps var in strings (ZEND_AST_DIM or ZEND_AST_VAR node) */ +/* ZEND_AST_VAR nodes can have any of the ZEND_ENCAPS_VAR_* flags */ +/* ZEND_AST_DIM flags can have ZEND_DIM_ALTERNATIVE_SYNTAX or ZEND_ENCAPS_VAR_DOLLAR_CURLY during the parse phase (ZEND_DIM_ALTERNATIVE_SYNTAX is a thrown fatal error). */ +#define ZEND_ENCAPS_VAR_DOLLAR_CURLY (1 << 0) +#define ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR (1 << 1) + /* Make sure these don't clash with ZEND_FETCH_CLASS_* flags. */ #define IS_CONSTANT_CLASS 0x400 /* __CLASS__ in trait */ #define IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE 0x800 @@ -1088,10 +1094,6 @@ static zend_always_inline bool zend_check_arg_send_type(const zend_function *zf, /* Attribute for ternary inside parentheses */ #define ZEND_PARENTHESIZED_CONDITIONAL 1 -/* Attributes for ${} encaps var in strings */ -#define ZEND_ENCAPS_VAR_DOLLAR_CURLY (1<<0) -#define ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR (1<<1) - /* For "use" AST nodes and the seen symbol table */ #define ZEND_SYMBOL_CLASS (1<<0) #define ZEND_SYMBOL_FUNCTION (1<<1)