Skip to content

Commit 292c23c

Browse files
committed
Output correct notice when deprecated curly braces are used with null coalescing operator
1 parent 4187838 commit 292c23c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Zend/tests/constant_expressions_coalesce.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ Constant expressions with null coalescing operator ??
55

66
const A = [1 => [[]]];
77

8+
// should produce deprecation notices
9+
const D_1 = null ?? A[1]{'undefined'}['index'] ?? 1;
10+
const D_2 = null ?? A['undefined']{'index'} ?? 2;
11+
const D_3 = null ?? A[1]{0}{2} ?? 3; // 2 deprecation notices
12+
const D_4 = A[1]{0} ?? 4;
13+
814
const T_1 = null ?? A[1]['undefined']['index'] ?? 1;
915
const T_2 = null ?? A['undefined']['index'] ?? 2;
1016
const T_3 = null ?? A[1][0][2] ?? 3;
1117
const T_4 = A[1][0][2] ?? 4;
1218
const T_5 = null ?? __LINE__;
1319
const T_6 = __LINE__ ?? "bar";
1420

21+
var_dump(D_1);
22+
var_dump(D_2);
23+
var_dump(D_3);
24+
var_dump(D_4);
25+
1526
var_dump(T_1);
1627
var_dump(T_2);
1728
var_dump(T_3);
@@ -31,6 +42,21 @@ var_dump((new class { public $var = A[1][0][2] ?? 4; })->var);
3142

3243
?>
3344
--EXPECTF--
45+
46+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
47+
48+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
49+
50+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
51+
52+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
53+
54+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
55+
int(1)
56+
int(2)
57+
int(3)
58+
array(0) {
59+
}
3460
int(1)
3561
int(2)
3662
int(3)

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
714714
zval_ptr_dtor_nogc(&op1);
715715
ret = FAILURE;
716716
} else {
717-
zend_fetch_dimension_const(result, &op1, &op2, (ast->attr == ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);
717+
zend_fetch_dimension_const(result, &op1, &op2, (ast->attr & ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);
718718

719719
zval_ptr_dtor_nogc(&op1);
720720
zval_ptr_dtor_nogc(&op2);

Zend/zend_compile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8748,7 +8748,7 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
87488748
case ZEND_AST_COALESCE:
87498749
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
87508750
if (ast->child[0]->kind == ZEND_AST_DIM) {
8751-
ast->child[0]->attr = ZEND_DIM_IS;
8751+
ast->child[0]->attr |= ZEND_DIM_IS;
87528752
}
87538753
zend_eval_const_expr(&ast->child[0]);
87548754

@@ -8802,13 +8802,13 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
88028802
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
88038803
}
88048804

8805-
if (ast->attr == ZEND_ALTERNATIVE_ARRAY_SYNTAX) {
8805+
if (ast->attr & ZEND_ALTERNATIVE_ARRAY_SYNTAX) {
88068806
zend_error(E_DEPRECATED, "Array and string offset access syntax with curly braces is deprecated");
88078807
}
88088808

88098809
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
8810-
if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
8811-
ast->child[0]->attr = ZEND_DIM_IS;
8810+
if (ast->attr & ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
8811+
ast->child[0]->attr |= ZEND_DIM_IS;
88128812
}
88138813

88148814
zend_eval_const_expr(&ast->child[0]);

0 commit comments

Comments
 (0)