-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Sniff basics | - |
---|---|
Fixable for PHP: | 7.1+ |
Sniff type: | Modernize |
Fixer type: | Safe |
Short description
PHP 7.1 introduced a short list syntax.
Related PHPCompatibility sniff(s):
ShortList
(open PR PHP 7.1: New sniff to detect short list syntax for symmetric array destructuring PHPCompatibility#654)
PHP manual references:
-
The shorthand array syntax ([]) may now be used to destructure arrays for assignments (including within foreach), as an alternative to the existing list() syntax, which is still supported.
Example code:
Detect the following code pattern(s):
list($id1, $name1) = $data[0];
foreach ($data as list($id, $name)) {
// logic here with $id and $name
}
And fix these to:
[$id1, $name1] = $data[0];
foreach ($data as [$id, $name]) {
// logic here with $id and $name
}