Skip to content

UnsupportedEmptyListAssignments ​

error on by default PHP ≥ 7.0

Group: Language level migration · PhpStorm name: UnsupportedEmptyListAssignmentsInspection

Since PHP 7.0 destructuring into a pattern that has no target at all (list(), list(, ), [], [, ]) is a compile-time fatal error. In a foreach value position this is easy to miss.

Example ​

php
<?php
foreach ($queue as list(, , )) {
    tick();
}
foreach ($queue as []) {
    tick();
}
foreach ($queue as list(, $second)) {
    use_it($second);
}
foreach ($queue as [$first]) {
    use_it($first);
}
list(, $only) = $queue;

Reported:

  • line 2: Empty destructuring pattern: PHP 7+ rejects this with a fatal error.
  • line 5: Empty destructuring pattern: PHP 7+ rejects this with a fatal error.

Configure ​

In custos.json:

json
{
  "rules": {
    "UnsupportedEmptyListAssignments": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore UnsupportedEmptyListAssignments

/**
 * @noinspection UnsupportedEmptyListAssignmentsInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.