PHP 7.1 Class Constant Visibility

Posted on by Gary Hockin

PHP 7.1 brought some changes to the way you can declare class level constants by giving the ability to mark them as `public`, `private` and `protected` like methods and parameters.

Visibility is important to make sure your code is used as expected when it’s extended by others, and ensure that things that shouldn’t be overwritten aren’t. Constants are important in this regard, in some cases overwriting constants is expected behavior to change default settings, in other cases constants are used internally and should never be changed when for example, you want to compare strings or set error levels.

PhpStorm 2017.2 brings this visibility change to the Extract to constant refactoring (CMD/CTRL+ALT+C). If the language level is set to PHP 7.1 (or newer) then the refactoring window will ask you the visibility of the constant you are creating.


– Gary & The PhpStorm Team



Subscribe for updates