1.2.112. Cant Overload Constants¶
It was not possible to overload class constants within a class, when the constant was defined in an interface.
<?php
interface i {
const A = 1;
}
//This lints, but doesn't executin in PHP 8.0 and older.
class x implements i {
const A = 1;
}
?>
See also interface constants <https://www.php.net/manual/en/language.oop5.interfaces.php#language.oop5.interfaces.constants>.
1.2.112.1. Suggestions¶
Avoid overloading constants
Define the constants only in the classes
1.2.112.2. Specs¶
Short name |
Interfaces/CantOverloadConstants |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, LintButWontExec |
Exakat since |
2.3.2 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Changed Behavior |
PHP 8.1 - More |
Precision |
High |
Features |
interface, class |
Note |
This issue may lint but will not run |
Available in |