Cannot assign to array(), use [] instead in %s¶
Description¶
The left array is actualy the list instruction. With that, PHP tries to assign each values of the array on the right to their same position on the left. In this case, there is an array, and it is not possible to assign directly to an array: it could be assigned to an element of that array, just not the whole array.
Example¶
<?php
[array($a)] = [array(42)];
var_dump($a);
?>
Solutions¶
Remove the array() on the left.
Remove the [] on the left.
Replace the
=with an==operator, to convert this into an assignation.
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>`_.