Skip to content

Commit e9068ce

Browse files
committed
Make empty list() check stricter
Now also includes list()s with just commas in it.
1 parent 41a249f commit e9068ce

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Zend/tests/list_empty_error.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Empty list() assignments are not allowed
3+
--FILE--
4+
<?php
5+
6+
list(,,,,,,,,,,) = [];
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Cannot use empty list in %s on line %d

Zend/zend_compile.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,10 +2191,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n
21912191
{
21922192
zend_ast_list *list = zend_ast_get_list(ast);
21932193
uint32_t i;
2194-
2195-
if (list->children == 1 && !list->child[0]) {
2196-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
2197-
}
2194+
zend_bool has_elems = 0;
21982195

21992196
for (i = 0; i < list->children; ++i) {
22002197
zend_ast *var_ast = list->child[i];
@@ -2203,6 +2200,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n
22032200
if (var_ast == NULL) {
22042201
continue;
22052202
}
2203+
has_elems = 1;
22062204

22072205
dim_node.op_type = IS_CONST;
22082206
ZVAL_LONG(&dim_node.u.constant, i);
@@ -2214,6 +2212,11 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n
22142212
zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
22152213
zend_emit_assign_znode(var_ast, &fetch_result);
22162214
}
2215+
2216+
if (!has_elems) {
2217+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
2218+
}
2219+
22172220
*result = *expr_node;
22182221
}
22192222
/* }}} */

0 commit comments

Comments
 (0)