1.2.1645. list() May Omit Variables¶
Simply omit any unused variable in a list() call.
list() is the only PHP function that accepts to have omitted arguments. If the following code makes no usage of a listed variable, just omit it.
<?php
// No need for '2', so no assignation
list ($a, , $b) = array(1, 2, 3);
// works with PHP 7.1 short syntax
[$a, , $b] = array(1, 2, 3);
// No need for '2', so no assignation
list ($a, $c, $b) = array(1, 2, 3);
?>
See also list.
1.2.1645.1. Connex PHP features¶
1.2.1645.1.1. Suggestions¶
Remove the unused variables from the list call
When the ignored values are at the beginning or the end of the array, array_slice() may be used to shorten the array.
1.2.1645.1.2. Specs¶
Short name |
Structures/ListOmissions |
Rulesets |
All, Analyze, CE, CI-checks, Suggestions |
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |