Skip to content

Commit e938af5

Browse files
committed
Improve test coverage and handle deprecated syntax in const expressions
1 parent f666b7d commit e938af5

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8802,6 +8802,10 @@ 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) {
8806+
zend_error(E_DEPRECATED, "Array and string offset access syntax with curly braces is deprecated");
8807+
}
8808+
88058809
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
88068810
if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
88078811
ast->child[0]->attr = ZEND_DIM_IS;

Zend/zend_compile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,9 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
991991
#define ZEND_ARRAY_NOT_PACKED (1<<1)
992992
#define ZEND_ARRAY_SIZE_SHIFT 2
993993

994+
/* Array/string access syntax with curly braces is used */
995+
#define ZEND_ALTERNATIVE_ARRAY_SYNTAX 1
996+
994997
/* Attribute for ternary inside parentheses */
995998
#define ZEND_PARENTHESIZED_CONDITIONAL 1
996999

@@ -1090,7 +1093,4 @@ END_EXTERN_C()
10901093

10911094
ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t opcode, zval *op1, zval *op2);
10921095

1093-
/* Array/string access syntax with curly braces is used */
1094-
#define ZEND_ALTERNATIVE_ARRAY_SYNTAX 1
1095-
10961096
#endif /* ZEND_COMPILE_H */

tests/strings/offsets_general.phpt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
11
--TEST--
22
testing the behavior of string offsets
3-
--INI--
4-
error_reporting=E_ALL
53
--FILE--
64
<?php
75
$string = "foobar";
6+
const FOO = "BAR"[0];
7+
var_dump(FOO);
88
var_dump($string[0]);
99
var_dump($string[1]);
1010
var_dump(isset($string[0]));
1111
var_dump(isset($string[0][0]));
1212
var_dump($string["foo"]);
1313
var_dump(isset($string["foo"]["bar"]));
14+
15+
const FOO_DEPRECATED = "BAR"{0};
16+
var_dump(FOO_DEPRECATED);
1417
var_dump($string{0});
18+
var_dump($string{1});
19+
var_dump(isset($string{0}));
20+
var_dump(isset($string{0}{0}));
21+
var_dump($string{"foo"});
22+
var_dump(isset($string{"foo"}{"bar"}));
1523
?>
1624
--EXPECTF--
1725

1826
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
27+
28+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
29+
30+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
31+
32+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
33+
34+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
35+
36+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
37+
38+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
39+
40+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
41+
42+
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
43+
string(1) "B"
1944
string(1) "f"
2045
string(1) "o"
2146
bool(true)
@@ -24,4 +49,12 @@ bool(true)
2449
Warning: Illegal string offset 'foo' in %s line %d
2550
string(1) "f"
2651
bool(false)
52+
string(1) "B"
53+
string(1) "f"
54+
string(1) "o"
55+
bool(true)
56+
bool(true)
57+
58+
Warning: Illegal string offset 'foo' in %s line %d
2759
string(1) "f"
60+
bool(false)

0 commit comments

Comments
 (0)