]> granicus.if.org Git - php/commitdiff
Make empty list() check stricter
authorNikita Popov <nikic@php.net>
Fri, 9 Jan 2015 17:27:06 +0000 (18:27 +0100)
committerNikita Popov <nikic@php.net>
Fri, 9 Jan 2015 17:27:06 +0000 (18:27 +0100)
Now also includes list()s with just commas in it.

Zend/tests/list_empty_error.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/list_empty_error.phpt b/Zend/tests/list_empty_error.phpt
new file mode 100644 (file)
index 0000000..78de2e9
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Empty list() assignments are not allowed
+--FILE--
+<?php
+
+list(,,,,,,,,,,) = [];
+
+?>
+--EXPECTF--
+Fatal error: Cannot use empty list in %s on line %d
index 16b5cfaf13d456bf57e866d07bdd50bb22a3ebc4..654c539d27820513586333a6d46297cd856cf6e7 100644 (file)
@@ -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;
 }
 /* }}} */