1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00

Fixed bug #62930, and more tests

This commit is contained in:
Xinchen Hui
2012-08-26 13:05:33 +08:00
parent c6a5d192c8
commit 5ebbdecfea
5 changed files with 56 additions and 1 deletions

View File

@@ -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 File

@@ -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 File

@@ -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 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 {