Skip to content

ShortListSyntaxCanBeUsed ​

info on by default quick-fix PHP ≥ 7.1

Group: Language level migration · PhpStorm name: ShortListSyntaxCanBeUsedInspection

From PHP 7.1 destructuring can use the short [...] form instead of list(...), consistent with short array syntax.

Example ​

php
<?php
list($host, $port) = explode(':', $addr);
list ('w' => $w, 'h' => $h) = $size;

foreach ($pairs as list($left, $right)) {
    swap($left, $right);
}
foreach ($grid as $row => list (, $cell)) {
    show($row, $cell);
}

while (list($key, $item) = each($legacy)) {
    use_it($key, $item);
}
[$p, $q] = $coords;
php
<?php
[$host, $port] = explode(':', $addr);
['w' => $w, 'h' => $h] = $size;

foreach ($pairs as [$left, $right]) {
    swap($left, $right);
}
foreach ($grid as $row => [, $cell]) {
    show($row, $cell);
}

while ([$key, $item] = each($legacy)) {
    use_it($key, $item);
}
[$p, $q] = $coords;

Reported:

  • line 2: Use short destructuring syntax '[...] = ...'.
  • line 3: Use short destructuring syntax '[...] = ...'.
  • line 5: Use short destructuring syntax in foreach ('as [...]').
  • line 8: Use short destructuring syntax in foreach ('as [...]').
  • line 12: Use short destructuring syntax '[...] = ...'.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore ShortListSyntaxCanBeUsed

/**
 * @noinspection ShortListSyntaxCanBeUsedInspection
 */

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