Skip to content

Commit 3b5b288

Browse files
committed
Add AST export support for nullsafe operator
Fixes oss-fuzz #24403 and variants.
1 parent d9f5c44 commit 3b5b288

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Zend/tests/assert/expect_015.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
5858
$x = C::$z;
5959
$x = ${$a . "_1"}::$z;
6060
$x = C::${$z . "_1"};
61+
$x?->y;
62+
$x?->y();
6163
}
6264
}
6365
}));
@@ -198,6 +200,8 @@ Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c,
198200
$x = C::$z;
199201
$x = ${$a . '_1'}::$z;
200202
$x = C::${$z . '_1'};
203+
$x?->y;
204+
$x?->y();
201205
}
202206

203207
}

Zend/zend_ast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
17921792
smart_str_appendc(str, ']');
17931793
break;
17941794
case ZEND_AST_PROP:
1795+
case ZEND_AST_NULLSAFE_PROP:
17951796
zend_ast_export_ex(str, ast->child[0], 0, indent);
1796-
smart_str_appends(str, "->");
1797+
smart_str_appends(str, ast->kind == ZEND_AST_NULLSAFE_PROP ? "?->" : "->");
17971798
zend_ast_export_var(str, ast->child[1], 0, indent);
17981799
break;
17991800
case ZEND_AST_STATIC_PROP:
@@ -2066,8 +2067,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
20662067

20672068
/* 3 child nodes */
20682069
case ZEND_AST_METHOD_CALL:
2070+
case ZEND_AST_NULLSAFE_METHOD_CALL:
20692071
zend_ast_export_ex(str, ast->child[0], 0, indent);
2070-
smart_str_appends(str, "->");
2072+
smart_str_appends(str, ast->kind == ZEND_AST_NULLSAFE_METHOD_CALL ? "?->" : "->");
20712073
zend_ast_export_var(str, ast->child[1], 0, indent);
20722074
smart_str_appendc(str, '(');
20732075
zend_ast_export_ex(str, ast->child[2], 0, indent);

0 commit comments

Comments
 (0)