From: Nikita Popov Date: Fri, 9 Jan 2015 17:27:06 +0000 (+0100) Subject: Make empty list() check stricter X-Git-Tag: PRE_PHP7_REMOVALS~31^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9068cefb4d97483823f8ee4dc384da7adf0c124;p=php Make empty list() check stricter Now also includes list()s with just commas in it. --- diff --git a/Zend/tests/list_empty_error.phpt b/Zend/tests/list_empty_error.phpt new file mode 100644 index 0000000000..78de2e950d --- /dev/null +++ b/Zend/tests/list_empty_error.phpt @@ -0,0 +1,10 @@ +--TEST-- +Empty list() assignments are not allowed +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use empty list in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 16b5cfaf13..654c539d27 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2191,10 +2191,7 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n { zend_ast_list *list = zend_ast_get_list(ast); uint32_t i; - - if (list->children == 1 && !list->child[0]) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list"); - } + zend_bool has_elems = 0; for (i = 0; i < list->children; ++i) { 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 if (var_ast == NULL) { continue; } + has_elems = 1; dim_node.op_type = IS_CONST; 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 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node); zend_emit_assign_znode(var_ast, &fetch_result); } + + if (!has_elems) { + zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list"); + } + *result = *expr_node; } /* }}} */