Skip to content
Browse files

Fixed bug #62930, and more tests

  • Loading branch information...
1 parent c6a5d19 commit 5ebbdecfeaaea1bc78450a2bb6d5ee280bf18dbd @laruence laruence committed Aug 26, 2012
View
0 Zend/tests/foreach_list.phpt → Zend/tests/foreach_list_001.phpt
File renamed without changes.
View
26 Zend/tests/foreach_list_002.phpt
@@ -0,0 +1,26 @@
+--TEST--
+foreach with freak lists
+--FILE--
+<?php
+
+foreach (array(array(1,2), array(3,4)) as list($a, )) {
+ var_dump($a);
+}
+
+$array = [['a', 'b'], 'c', 'd'];
+
+foreach($array as list(list(), $a)) {
+ var_dump($a);
+}
+
+?>
+--EXPECTF--
+int(1)
+int(3)
+string(1) "b"
+
+Notice: Uninitialized string offset: 1 in %sforeach_list_002.php on line %d
+string(0) ""
+
+Notice: Uninitialized string offset: 1 in %sforeach_list_002.php on line %d
+string(0) ""
View
13 Zend/tests/foreach_list_003.phpt
@@ -0,0 +1,13 @@
+--TEST--
+foreach with list key
+--FILE--
+<?php
+
+$array = [['a', 'b'], 'c', 'd'];
+
+foreach($array as list($key) => list(list(), $a)) {
+}
+
+?>
+--EXPECTF--
+Fatal error: Cannot use list as key element in %sforeach_list_003.php on line %d
View
13 Zend/tests/foreach_list_004.phpt
@@ -0,0 +1,13 @@
+--TEST--
+foreach with empty list
+--FILE--
+<?php
+
+$array = [['a', 'b'], 'c', 'd'];
+
+foreach($array as $key => list()) {
+}
+
+?>
+--EXPECTF--
+Fatal error: Cannot use empty list in %sforeach_list_004.php on line %d
View
5 Zend/zend_compile.c
@@ -6288,7 +6288,7 @@ void zend_do_foreach_cont(znode *foreach_token, const znode *open_brackets_token
zend_error(E_COMPILE_ERROR, "Key element cannot be a reference");
}
if (key->EA & ZEND_PARSED_LIST_EXPR) {
- zend_error(E_COMPILE_ERROR, "Cannot use list as Key element");
+ zend_error(E_COMPILE_ERROR, "Cannot use list as key element");
}
}
@@ -6326,6 +6326,9 @@ void zend_do_foreach_cont(znode *foreach_token, const znode *open_brackets_token
GET_NODE(&value_node, opline->result);
if (value->EA & ZEND_PARSED_LIST_EXPR) {
+ if (!CG(list_llist).head) {
+ zend_error(E_COMPILE_ERROR, "Cannot use empty list");
+ }
zend_do_list_end(&dummy, &value_node TSRMLS_CC);
zend_do_free(&dummy TSRMLS_CC);
} else {

0 comments on commit 5ebbdec

Please sign in to comment.
Something went wrong with that request. Please try again.