1.2.221. Const Visibility Usage¶
Visibility for class constant controls the accessibility to class constant.
A public constant may be used anywhere in the code; a protected constant usage is restricted to the class and its relatives; a private constant is restricted to itself.
This feature was introduced in PHP 7.1. It is recommended to use explicit visibility, and, whenever possible, make the visibility private.
<?php
class x {
public const a = 1;
protected const b = 2;
private const c = 3;
const d = 4;
}
interface i {
public const a = 1;
const d = 4;
}
?>
See also Class Constants and PHP RFC: Support Class Constant Visibility.
1.2.221.1. Connex PHP features¶
1.2.221.1.1. Suggestions¶
Add constant visibility, at least ‘public’.
1.2.221.1.2. Specs¶
Short name |
Classes/ConstVisibilityUsage |
Rulesets |
All, Appinfo, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70 |
Exakat since |
1.3.0 |
PHP Version |
With PHP 7.1 and more recent |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Available in |