1.2.279. Could Drop Variable¶
Suggest removing the variable in catch clause where the variable is not used. The type of the exception is sufficient to make the catch clause work. Although, it is recommended to use the caught exception, for chaining or logging, for example.
<?php
try {
doSomething();
} catch(Exception1 $e) {
// No usage of $e : just drop it from the clause
} catch(Exception2 $e2) {
// $e2 is caught and used.
echo $e2->getMessage();
}
?>
1.2.279.1. Connex PHP features¶
1.2.279.1.1. Suggestions¶
Remove the unused variable
1.2.279.1.2. Specs¶
Short name |
Exceptions/CouldDropVariable |
Rulesets |
|
Exakat since |
2.6.4 |
PHP Version |
With PHP 8.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |