summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-01-09 18:27:06 +0100
committerNikita Popov <nikic@php.net>2015-01-09 18:27:06 +0100
commite9068cefb4d97483823f8ee4dc384da7adf0c124 (patch)
treed419c09fa770968ff164faa54ab4925167a0379c
parent41a249fef602b8cbfdc70fc8179e48cc1387b821 (diff)
downloadphp-git-e9068cefb4d97483823f8ee4dc384da7adf0c124.tar.gz
Make empty list() check stricter
Now also includes list()s with just commas in it.
-rw-r--r--Zend/tests/list_empty_error.phpt10
-rw-r--r--Zend/zend_compile.c11
2 files changed, 17 insertions, 4 deletions
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--
+<?php
+
+list(,,,,,,,,,,) = [];
+
+?>
+--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;
}
/* }}} */