diff --git a/lib/PhpParser/ConstExprEvaluator.php b/lib/PhpParser/ConstExprEvaluator.php index 7f02e6f..7131c3d 100644 --- a/lib/PhpParser/ConstExprEvaluator.php +++ b/lib/PhpParser/ConstExprEvaluator.php @@ -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); } diff --git a/test/PhpParser/ConstExprEvaluatorTest.php b/test/PhpParser/ConstExprEvaluatorTest.php index 23ab18d..f73b262 100644 --- a/test/PhpParser/ConstExprEvaluatorTest.php +++ b/test/PhpParser/ConstExprEvaluatorTest.php @@ -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],