Skip to content

Commit 24218f8

Browse files
committed
Add blocks to ?? and ??=
1 parent aaf836b commit 24218f8

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Zend/tests/block_expr/coalesce.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Coalesce block
3+
--FILE--
4+
<?php
5+
$x = null;
6+
$y = $x ?? {
7+
echo "Executed\n";
8+
42
9+
};
10+
var_dump($y);
11+
12+
$x = 42;
13+
$y = $x ?? {
14+
echo "Never executed\n";
15+
};
16+
var_dump($y);
17+
?>
18+
--EXPECT--
19+
Executed
20+
int(42)
21+
int(42)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Coalesce assignment block
3+
--FILE--
4+
<?php
5+
$x = null;
6+
$x ??= {
7+
echo "Executed\n";
8+
42
9+
};
10+
var_dump($x);
11+
12+
$x = 42;
13+
$x ??= {
14+
echo "Never executed\n";
15+
};
16+
var_dump($x);
17+
?>
18+
--EXPECT--
19+
Executed
20+
int(42)
21+
int(42)

Zend/zend_language_parser.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ expr:
11791179
{ $$ = zend_ast_create_assign_op(ZEND_SR, $1, $3); }
11801180
| variable T_COALESCE_EQUAL expr
11811181
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
1182+
| variable T_COALESCE_EQUAL block_expr
1183+
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
11821184
| variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }
11831185
| T_INC variable { $$ = zend_ast_create(ZEND_AST_PRE_INC, $2); }
11841186
| variable T_DEC { $$ = zend_ast_create(ZEND_AST_POST_DEC, $1); }
@@ -1244,6 +1246,8 @@ expr:
12441246
{ $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, NULL, $4); }
12451247
| expr T_COALESCE expr
12461248
{ $$ = zend_ast_create(ZEND_AST_COALESCE, $1, $3); }
1249+
| expr T_COALESCE block_expr
1250+
{ $$ = zend_ast_create(ZEND_AST_COALESCE, $1, $3); }
12471251
| internal_functions_in_yacc { $$ = $1; }
12481252
| T_INT_CAST expr { $$ = zend_ast_create_cast(IS_LONG, $2); }
12491253
| T_DOUBLE_CAST expr { $$ = zend_ast_create_cast(IS_DOUBLE, $2); }

0 commit comments

Comments
 (0)