Assignments can only happen to writable values¶
Description¶
With the list() operator, the right part of the => operator must be a variable or equivalent. The corresponding value on the right part of the assignation will be stored there, so it has to be a data container. It is possible to use a variable, property (static or not), an array element or an array append.
The same error may happen when the property is not available: this may be the case with a nullsafe operator.
This is valid with or without the index part, in the list() call.
Example¶
<?php
// short array syntax : the left part is not an array, but a list()
[1] = [2];
['a' => 1] = ['a' => 2];
list('a' => 1) = array('a' => 2);
// ?-> may be returning null, and not a valid container.
[$foo?->bar->baz] = ['bar'];
?>
Solutions¶
Use a variable.
Use an array append.
Use a a property.