]> granicus.if.org Git - php/commitdiff
Fixed bug #62930, and more tests
authorXinchen Hui <laruence@php.net>
Sun, 26 Aug 2012 05:05:33 +0000 (13:05 +0800)
committerXinchen Hui <laruence@php.net>
Sun, 26 Aug 2012 05:05:33 +0000 (13:05 +0800)
Zend/tests/foreach_list_001.phpt [moved from Zend/tests/foreach_list.phpt with 100% similarity]
Zend/tests/foreach_list_002.phpt [new file with mode: 0644]
Zend/tests/foreach_list_003.phpt [new file with mode: 0644]
Zend/tests/foreach_list_004.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/foreach_list_002.phpt b/Zend/tests/foreach_list_002.phpt
new file mode 100644 (file)
index 0000000..251870b
--- /dev/null
@@ -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) ""
diff --git a/Zend/tests/foreach_list_003.phpt b/Zend/tests/foreach_list_003.phpt
new file mode 100644 (file)
index 0000000..8674ecd
--- /dev/null
@@ -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
diff --git a/Zend/tests/foreach_list_004.phpt b/Zend/tests/foreach_list_004.phpt
new file mode 100644 (file)
index 0000000..fd48e8a
--- /dev/null
@@ -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
index d8257927fded8d03cd173a28ad116351430f2a04..704db107cac4a5542cb63eb28d73fc6b1d19413e 100644 (file)
@@ -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 {