Skip to content

Commit 6a50af2

Browse files
authored
Make "{$g{'h'}}" emit fatal error and no incorrect deprecation notice in 8.2 (#9264)
The ast node flag constants ZEND_DIM_ALTERNATIVE_SYNTAX and ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR node have identical values (1<<1), causing a deprecation notice to be incorrectly emitted before the fatal error for unsupported syntax. Fixes GH-9263 Explicitly check for AST_VAR/AST_DIM kind for future compatibility `AST_PROP`/`AST_METHOD_CALL` and nullsafe variants can also be found in encapsulated strings - currently they have no flags but they may have flags in the future. This also clarifies that this deprecation warning can only happen for AST_VAR/AST_DIM nodes for certain `attr` values.
1 parent d013d94 commit 6a50af2

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed incorrect double to long casting in latest clang. (zeriyoshi)
77
. Added support for defining constants in traits. (sj-i)
8+
. Stop incorrectly emitting false positive deprecation notice alongside
9+
unsupported syntax fatal error for `"{$g{'h'}}"`. (TysonAndre)
810

911
- MBString:
1012
. Fixed bug GH-9248 (Segmentation fault in mb_strimwidth()). (cmb)
@@ -76,7 +78,7 @@ PHP NEWS
7678
$advance). (Anton Smirnov)
7779
. Changed Mt19937 to throw a ValueError instead of InvalidArgumentException
7880
for invalid $mode. (timwolla)
79-
. Splitted Random\Randomizer::getInt() (without arguments) to
81+
. Splitted Random\Randomizer::getInt() (without arguments) to
8082
Random\Randomizer::nextInt(). (zeriyoshi)
8183

8284
- Sockets:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--TEST--
2+
Alternative offset syntax should emit only E_COMPILE_ERROR in string interpolation
3+
--FILE--
4+
<?php "{$g{'h'}}"; ?>
5+
--EXPECTF--
6+
Fatal error: Array and string offset access syntax with curly braces is no longer supported in %s on line 1

Zend/zend_compile.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9623,11 +9623,12 @@ static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
96239623
last_const_node.op_type = IS_UNUSED;
96249624
for (i = 0; i < list->children; i++) {
96259625
zend_ast *encaps_var = list->child[i];
9626+
96269627
if (encaps_var->attr & (ZEND_ENCAPS_VAR_DOLLAR_CURLY|ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR)) {
9627-
if (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR) {
9628-
zend_error(E_DEPRECATED, "Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead");
9629-
} else {
9628+
if ((encaps_var->kind == ZEND_AST_VAR || encaps_var->kind == ZEND_AST_DIM) && (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY)) {
96309629
zend_error(E_DEPRECATED, "Using ${var} in strings is deprecated, use {$var} instead");
9630+
} else if (encaps_var->kind == ZEND_AST_VAR && (encaps_var->attr & ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR)) {
9631+
zend_error(E_DEPRECATED, "Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead");
96319632
}
96329633
}
96339634

Zend/zend_compile.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,15 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
10161016
#define ZEND_ARG_TYPE_IS_TENTATIVE(arg_info) \
10171017
((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_TENTATIVE_BIT) != 0)
10181018

1019-
#define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce */
1019+
#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. */
10201020
#define ZEND_DIM_ALTERNATIVE_SYNTAX (1 << 1) /* deprecated curly brace usage */
10211021

1022+
/* Attributes for ${} encaps var in strings (ZEND_AST_DIM or ZEND_AST_VAR node) */
1023+
/* ZEND_AST_VAR nodes can have any of the ZEND_ENCAPS_VAR_* flags */
1024+
/* 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). */
1025+
#define ZEND_ENCAPS_VAR_DOLLAR_CURLY (1 << 0)
1026+
#define ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR (1 << 1)
1027+
10221028
/* Make sure these don't clash with ZEND_FETCH_CLASS_* flags. */
10231029
#define IS_CONSTANT_CLASS 0x400 /* __CLASS__ in trait */
10241030
#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,
10881094
/* Attribute for ternary inside parentheses */
10891095
#define ZEND_PARENTHESIZED_CONDITIONAL 1
10901096

1091-
/* Attributes for ${} encaps var in strings */
1092-
#define ZEND_ENCAPS_VAR_DOLLAR_CURLY (1<<0)
1093-
#define ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR (1<<1)
1094-
10951097
/* For "use" AST nodes and the seen symbol table */
10961098
#define ZEND_SYMBOL_CLASS (1<<0)
10971099
#define ZEND_SYMBOL_FUNCTION (1<<1)

0 commit comments

Comments
 (0)