1.2.730. Multiple Constant Definition¶
Some constants are defined several times in your code. This will lead to a fatal error, if they are defined during the same execution.
Multiple definitions may happens at bootstrap, when the application code is collecting information about the current environment. It may also happen at inclusion time, which one set of constant being loaded, while other definition are not, avoiding conflict. Both are false positive.
<?php
// OS is defined twice.
if (PHP_OS == 'Windows') {
define('OS', 'Win');
} else {
define('OS', 'Other');
}
?>
See also class.
1.2.730.1. Connex PHP features¶
1.2.730.1.1. Suggestions¶
Move the constants to a class, and include the right class based on control flow.
Give different names to the constants, and keep the condition close to utilisation.
Move the constants to an external configuration file : it will be easier to identify that those constants may change.
1.2.730.1.2. Specs¶
Short name |
Constants/MultipleConstantDefinition |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |