1.2.844. No isset() With empty()¶
empty() actually does the job of isset() too.
From the manual : No warning is generated if the variable does not exist. That means empty() is essentially the concise equivalent to !`isset( <https://www.www.php.net/isset>`_$var) || $var == false.
The main difference is that isset() only works with variables, while empty() works with other structures, such as constants.
<?php
// Enough validation
if (!empty($a)) {
doSomething();
}
// Too many tests
if (isset($a) && !empty($a)) {
doSomething();
}
?>
1.2.844.1. Suggestions¶
Only use isset(), just drop the empty()
Only use empty(), just drop the empty()
Use a null value, so the variable is always set
1.2.844.2. Specs¶
Short name |
Structures/NoIssetWithEmpty |
Rulesets |
|
Exakat since |
0.8.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Features |
class |
Examples |
|
Available in |