Fixed array value evaluation with unpacked array

This commit is contained in:
Jaroslav Hanslík 2021-10-11 19:35:41 +02:00 committed by Nikita Popov
parent 8da6d7ac62
commit 54f19a0a66
2 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace PhpParser;
use function array_merge;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
@ -150,6 +151,8 @@ class ConstExprEvaluator
foreach ($expr->items as $item) {
if (null !== $item->key) {
$array[$this->evaluate($item->key)] = $this->evaluate($item->value);
} elseif ($item->unpack) {
$array = array_merge($array, $this->evaluate($item->value));
} else {
$array[] = $this->evaluate($item->value);
}

View File

@ -22,6 +22,9 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase
['"foo"', "foo"],
['[0, 1]', [0, 1]],
['["foo" => "bar"]', ["foo" => "bar"]],
['[...["bar"]]', ["bar"]],
['[...["foo" => "bar"]]', ["foo" => "bar"]],
['["a", "b" => "b", ...["b" => "bb", "c"]]', ["a", "b" => "bb", "c"]],
['NULL', null],
['False', false],
['true', true],