1.2.576. Inherited Class Constant Visibility¶
Visibility of class constant must be public, even when overwritten.
This was not checked until PHP 8.3, where it is now a Fatal Error. When the interface and the class are defined in different files, the error appears at execution time.
<?php
interface i {
public const I = 1;
public const J = 2;
}
class x implements i {
// This should not be possible
private const I = 10;
public const J = 20;
}
?>
1.2.576.2. Connex PHP features¶
1.2.576.2.1. Suggestions¶
Set the constant visibility in the class to public
Remove the visibility of the constant in the class
Remove the implementation of the interface in the class
1.2.576.2.2. Specs¶
Short name |
Interfaces/InheritedClassConstantVisibility |
Rulesets |
|
Exakat since |
2.5.3 |
PHP Version |
8.2 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |