Skip to content

Commit 0bd7cc8

Browse files
committed
Stip null elements from AST_STMT_LIST
1 parent 7b78bf1 commit 0bd7cc8

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ Version changelog
420420
* For `AST_NAME` nodes with `NAME_FQ` the leading backslash is now dropped if syntax like
421421
`('\bar')()` is used. Previously this would return the name as `'\bar'`, while a normal `\bar()`
422422
call would return it as `'bar'`. Now always the latter form is used.
423+
* `null` elements are now stripped from `AST_STMT_LIST`. Previously these could be caused by nop
424+
statements (`;`).
423425

424426
### 30 (current)
425427

ast.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,14 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, zend_long version
211211
!is_list && version >= 30 ? ast_kind_child_name(ast->kind, i) : NULL;
212212
zval child_zv;
213213

214-
if (version >= 20 && ast->kind == ZEND_AST_STMT_LIST
215-
&& child != NULL && child->kind == ZEND_AST_STMT_LIST) {
216-
ast_fill_children_ht(ht, child, version);
217-
continue;
214+
if (version >= 20 && ast->kind == ZEND_AST_STMT_LIST) {
215+
if (child != NULL && child->kind == ZEND_AST_STMT_LIST) {
216+
ast_fill_children_ht(ht, child, version);
217+
continue;
218+
}
219+
if (version >= 40 && child == NULL) {
220+
continue;
221+
}
218222
}
219223

220224
if (ast_is_name(child, ast, i)) {

tests/nop_statements.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Nop statements
3+
--FILE--
4+
<?php
5+
6+
require __DIR__ . '/../util.php';
7+
8+
$code = <<<'PHP'
9+
<?php
10+
$a;
11+
;
12+
$b;
13+
PHP;
14+
15+
echo ast_dump(ast\parse_code($code, $version=30)), "\n";
16+
echo ast_dump(ast\parse_code($code, $version=40)), "\n";
17+
18+
?>
19+
--EXPECT--
20+
AST_STMT_LIST
21+
0: AST_VAR
22+
name: "a"
23+
1: null
24+
2: AST_VAR
25+
name: "b"
26+
AST_STMT_LIST
27+
0: AST_VAR
28+
name: "a"
29+
1: AST_VAR
30+
name: "b"

0 commit comments

Comments
 (0)