Argument unpacking in constant expressions is not supported

Description

It is not possible to use the ... operator in an static constant expression, with the new operator.

On the other hand, it is possible to use it inside arrays to spread the elements. It is also possible to use it in a closure definition.

Example

<?php

const A = [1,2,3];

function foo($a = new C(...A)) {}

function goo($a = [...A, ...A])) {}


?>

Solutions

  • Access the array elements individually.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.