- 在AssignOpTrait.php中导入ArrayItem类并更新类型检查 - 在CompilerBase.php中添加parseForeachItemAsList方法处理列表解构 - 在CompilerBase.php中修改parseForeachArray方法支持List_节点 - 在Translator.php中扩展foreach循环翻译逻辑以处理列表解构 - 添加foreach-list.phpt和iterator-list.phpt测试用例验证功能pull/1/head
parent
dce5190422
commit
6a1fb828f8
5 changed files with 93 additions and 9 deletions
@ -0,0 +1,19 @@ |
|||||||
|
--TEST-- |
||||||
|
foreach with list/array destructuring syntax |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
function main() { |
||||||
|
$array = []; |
||||||
|
$array[] = ['foo', 'elem1']; |
||||||
|
$array[] = ['bar', 'elem2']; |
||||||
|
foreach (array_reverse($array) as [$v1, $v2]) { |
||||||
|
var_dump($v1, $v2); |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "bar" |
||||||
|
string(5) "elem2" |
||||||
|
string(3) "foo" |
||||||
|
string(5) "elem1" |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
--TEST-- |
||||||
|
foreach with list destructuring on Traversable object |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
function main() { |
||||||
|
$array = new ArrayObject(); |
||||||
|
$array[] = ['foo', 'elem1']; |
||||||
|
$array[] = ['bar', 'elem2']; |
||||||
|
foreach ($array as [$v1, $v2]) { |
||||||
|
var_dump($v1, $v2); |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(3) "foo" |
||||||
|
string(5) "elem1" |
||||||
|
string(3) "bar" |
||||||
|
string(5) "elem2" |
||||||
Loading…
Reference in new issue