Skip to content

Commit 81e2938

Browse files
committed
Fix issue nikic#36
The emulation of PHP 7.0 list() structure did not account for skipped elements.
1 parent 9e9569c commit 81e2938

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static inline zend_bool ast_array_is_list(zend_ast *ast) {
241241
}
242242

243243
for (i = 0; i < list->children; i++) {
244-
if (list->child[i]->child[1] != NULL || list->child[i]->attr) {
244+
if (list->child[i] && (list->child[i]->child[1] != NULL || list->child[i]->attr)) {
245245
return 0;
246246
}
247247
}
@@ -400,7 +400,7 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, zend_long version
400400
/* Skip docComment child -- It's handled separately */
401401
continue;
402402
#if PHP_VERSION_ID >= 70100
403-
} else if (ast->kind == ZEND_AST_LIST) {
403+
} else if (ast->kind == ZEND_AST_LIST && child != NULL) {
404404
/* Emulate simple variable list */
405405
ast_to_zval(&child_zv, child->child[0], version);
406406
#else

tests/array_destructuring_old.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require __DIR__ . '/../util.php';
88
$code = <<<'PHP'
99
<?php
1010
list($a, $b) = $x;
11+
list(, $b) = $x;
1112
PHP;
1213

1314
echo ast_dump(ast\parse_code($code, $version=30)), "\n";
@@ -24,6 +25,13 @@ AST_STMT_LIST
2425
name: "b"
2526
expr: AST_VAR
2627
name: "x"
28+
1: AST_ASSIGN
29+
var: AST_LIST
30+
0: null
31+
1: AST_VAR
32+
name: "b"
33+
expr: AST_VAR
34+
name: "x"
2735
AST_STMT_LIST
2836
0: AST_ASSIGN
2937
var: AST_ARRAY
@@ -40,3 +48,14 @@ AST_STMT_LIST
4048
key: null
4149
expr: AST_VAR
4250
name: "x"
51+
1: AST_ASSIGN
52+
var: AST_ARRAY
53+
flags: ARRAY_SYNTAX_LIST (1)
54+
0: null
55+
1: AST_ARRAY_ELEM
56+
flags: 0
57+
value: AST_VAR
58+
name: "b"
59+
key: null
60+
expr: AST_VAR
61+
name: "x"

0 commit comments

Comments
 (0)