mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
Add tests for list() in assignment in array literals
Array literals will constant evaluate their elements. These can include assignments, even though these are not valid constant expressions. The lhs of assignments can be a list() element (or []) which is parsed as an array with a special flag.
This commit is contained in:
parent
58a191c659
commit
8ed66b4347
28
Zend/tests/gh11320_1.phpt
Normal file
28
Zend/tests/gh11320_1.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
GH-11320: Array literals can contain list() assignments
|
||||
--FILE--
|
||||
<?php
|
||||
$index = 1;
|
||||
function getList() { return [2, 3]; }
|
||||
var_dump([$index => list($x, $y) = getList()]);
|
||||
var_dump([$index => [$x, $y] = getList()]);
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(3)
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(3)
|
||||
}
|
||||
}
|
12
Zend/tests/gh11320_2.phpt
Normal file
12
Zend/tests/gh11320_2.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
GH-11320: list() expressions can contain magic constants
|
||||
--FILE--
|
||||
<?php
|
||||
[list(__FILE__ => $foo) = [__FILE__ => 'foo']];
|
||||
var_dump($foo);
|
||||
[[__FILE__ => $foo] = [__FILE__ => 'foo']];
|
||||
var_dump($foo);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(3) "foo"
|
||||
string(3) "foo"
|
8
Zend/tests/gh11320_3.phpt
Normal file
8
Zend/tests/gh11320_3.phpt
Normal file
@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
GH-11320: list() must not appear as a standalone array element
|
||||
--FILE--
|
||||
<?php
|
||||
[list($a)];
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Cannot use list() as standalone expression in %s on line %d
|
Loading…
Reference in New Issue
Block a user