| Sniff basics |
- |
| Fixable for PHP: |
7.1+ |
| Sniff type: |
Modernize |
| Fixer type: |
Safe (review recommended) |
Short description of the sniff
Prior to PHP 7.1, class constants could not have visibility declared and would always be public. As of PHP 7.1, there is a choice between declaring class constants as public, protected or private.
Related PHPCompatibility sniff(s):
PHP manual references:
Example code:
Detect the following code pattern(s):
class ClassConstants
{
const MYCONST_A = 1;
}
And fix these to:
class ClassConstants
{
public const MYCONST_A = 1;
}
Notes for implementation of the sniff:
- This is only possible for class constants, so the scope of the
const keyword will need to be carefully checked.
Short description of the sniff
Prior to PHP 7.1, class constants could not have visibility declared and would always be public. As of PHP 7.1, there is a choice between declaring class constants as
public,protectedorprivate.Related PHPCompatibility sniff(s):
NewConstVisibilityPHP manual references:
http://php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-constants
http://php.net/manual/en/migration71.new-features.php#migration71.new-features.class-constant-visibility
http://php.net/manual/en/language.oop5.constants.php
Example code:
Detect the following code pattern(s):
And fix these to:
Notes for implementation of the sniff:
constkeyword will need to be carefully checked.