Skip to content

RFC Proposal: ??= equal null coalesce operator #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ static void zend_ast_export_ex(smart_str *str, zend_ast *ast, int priority, int
case ZEND_ASSIGN_SL: BINARY_OP(" <<= ", 90, 91, 90);
case ZEND_ASSIGN_SR: BINARY_OP(" >>= ", 90, 91, 90);
case ZEND_ASSIGN_CONCAT: BINARY_OP(" .= ", 90, 91, 90);
case ZEND_ASSIGN_COALESCE: BINARY_OP(" ??= ", 90, 91, 90);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
insertion breaks other lines BINARY_OP alignment.

case ZEND_ASSIGN_BW_OR: BINARY_OP(" |= ", 90, 91, 90);
case ZEND_ASSIGN_BW_AND: BINARY_OP(" &= ", 90, 91, 90);
case ZEND_ASSIGN_BW_XOR: BINARY_OP(" ^= ", 90, 91, 90);
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(void)
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_COALESCE:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
Expand All @@ -1582,6 +1583,7 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(void)
case ZEND_ASSIGN_SL:
case ZEND_ASSIGN_SR:
case ZEND_ASSIGN_CONCAT:
case ZEND_ASSIGN_COALESCE:
case ZEND_ASSIGN_BW_OR:
case ZEND_ASSIGN_BW_AND:
case ZEND_ASSIGN_BW_XOR:
Expand Down
5 changes: 4 additions & 1 deletion Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%right T_YIELD
%right T_DOUBLE_ARROW
%right T_YIELD_FROM
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL T_COALESCE_EQUAL
%left '?' ':'
%right T_COALESCE
%left T_BOOLEAN_OR
Expand Down Expand Up @@ -219,6 +219,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%token T_NS_SEPARATOR "\\ (T_NS_SEPARATOR)"
%token T_ELLIPSIS "... (T_ELLIPSIS)"
%token T_COALESCE "?? (T_COALESCE)"
%token T_COALESCE_EQUAL "??= (T_COALESCE_EQUAL)"
%token T_POW "** (T_POW)"
%token T_POW_EQUAL "**= (T_POW_EQUAL)"

Expand Down Expand Up @@ -886,6 +887,8 @@ expr_without_variable:
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SL, $1, $3); }
| variable T_SR_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_SR, $1, $3); }
| variable T_COALESCE_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_COALESCE, $1, $3); }
| variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }
| T_INC variable { $$ = zend_ast_create(ZEND_AST_PRE_INC, $2); }
| variable T_DEC { $$ = zend_ast_create(ZEND_AST_POST_DEC, $1); }
Expand Down
Loading