Cannot use list() as standalone expression¶
Description¶
list() assigns values from an array to a list of variables (or data containers). As such, it is a write operation, which should be on the left side of an assignment, or in other write positions, such as a foreach() blind variables or inside another list. list() cannot be used in a read position, as in the code example: list() as not result.
list() also has a short syntax version, []
. That short syntax is converted to an array automatically, so it doesn’t yield any error then.
Example¶
<?php
[list($a)];
// the second [] is not a list() but an array().
[[$a]];
?>
Solutions¶
Use array() or [] instead.