Skip to content

Commit cbc90b1

Browse files
committed
Merge branch 'deprecate_concat_add_sub' into PHP-8.4
2 parents ab2710c + 3b23694 commit cbc90b1

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

Zend/zend_ast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
17331733
case ZEND_MOD: BINARY_OP(" % ", 210, 210, 211);
17341734
case ZEND_SL: BINARY_OP(" << ", 190, 190, 191);
17351735
case ZEND_SR: BINARY_OP(" >> ", 190, 190, 191);
1736+
case ZEND_PARENTHESIZED_CONCAT: /* fallthrough */
17361737
case ZEND_CONCAT: BINARY_OP(" . ", 200, 200, 201);
17371738
case ZEND_BW_OR: BINARY_OP(" | ", 140, 140, 141);
17381739
case ZEND_BW_AND: BINARY_OP(" & ", 160, 160, 161);

Zend/zend_compile.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7069,6 +7069,16 @@ void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
70697069
zend_ast *right_ast = ast->child[1];
70707070
uint32_t opcode = ast->attr;
70717071

7072+
if ((opcode == ZEND_ADD || opcode == ZEND_SUB) && left_ast->kind == ZEND_AST_BINARY_OP && left_ast->attr == ZEND_CONCAT) {
7073+
zend_error(E_DEPRECATED, "The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence");
7074+
}
7075+
if ((opcode == ZEND_SL || opcode == ZEND_SR) && ((left_ast->kind == ZEND_AST_BINARY_OP && left_ast->attr == ZEND_CONCAT) || (right_ast->kind == ZEND_AST_BINARY_OP && right_ast->attr == ZEND_CONCAT))) {
7076+
zend_error(E_DEPRECATED, "The behavior of unparenthesized expressions containing both '.' and '>>'/'<<' will change in PHP 8: '<<'/'>>' will take a higher precedence");
7077+
}
7078+
if (opcode == ZEND_PARENTHESIZED_CONCAT) {
7079+
opcode = ZEND_CONCAT;
7080+
}
7081+
70727082
znode left_node, right_node;
70737083
zend_compile_expr(&left_node, left_ast);
70747084
zend_compile_expr(&right_node, right_ast);

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,11 +980,11 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
980980
#define ZEND_SYMBOL_CONST (1<<2)
981981

982982
/* Pseudo-opcodes that are used only temporarily during compilation */
983+
#define ZEND_PARENTHESIZED_CONCAT 252 /* removed with PHP 8 */
983984
#define ZEND_GOTO 253
984985
#define ZEND_BRK 254
985986
#define ZEND_CONT 255
986987

987-
988988
END_EXTERN_C()
989989

990990
#define ZEND_CLONE_FUNC_NAME "__clone"

Zend/zend_language_parser.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ expr:
964964
| '(' expr ')' {
965965
$$ = $2;
966966
if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr = ZEND_PARENTHESIZED_CONDITIONAL;
967+
if ($$->kind == ZEND_AST_BINARY_OP && $$->attr == ZEND_CONCAT) $$->attr = ZEND_PARENTHESIZED_CONCAT;
967968
}
968969
| new_expr { $$ = $1; }
969970
| expr '?' expr ':' expr

Zend/zend_opcode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ ZEND_API binary_op_type get_binary_op(int opcode)
10491049
case ZEND_SR:
10501050
case ZEND_ASSIGN_SR:
10511051
return (binary_op_type) shift_right_function;
1052+
case ZEND_PARENTHESIZED_CONCAT:
10521053
case ZEND_FAST_CONCAT:
10531054
case ZEND_CONCAT:
10541055
case ZEND_ASSIGN_CONCAT:

0 commit comments

Comments
 (0)