1.2.233. Constant Typo Looks Like A Variable¶
A constant bears the same name as a variable. This might be a typo.
When the constant doesn’t exist, PHP 8.0 yields a Fatal Error and stops execution. PHP 7.4 turns the undefined constant into its string equivalent. This analysis is case sensitive.
<?php
// Get an object or null
$object = foo();
// PHP 8.0 stops here, with a Fatal Error
// PHP 7.4 makes this a string, and the condition is always true
if (!empty(object)) {
// In PHP 7.4, this is not protected by the condition, and may yield an error.
$object->doSomething();
}
?>
1.2.233.1. Connex PHP features¶
1.2.233.1.1. Suggestions¶
Add a $ sign to the constant
Use a different name for the variable, or the constant
1.2.233.1.2. Specs¶
Short name |
Variables/ConstantTypo |
Rulesets |
|
Exakat since |
2.2.0 |
PHP Version |
With PHP 8.0 and older |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Related rule |
|
Available in |