PhpStorm 2018.1 Help

Extract Constant Dialog

Refactor | Extract Constant
Ctrl+Alt+C

ItemDescription
NameIn this text box, specify the name of the new constant.
Replace all occurrencesSelect this checkbox to have PhpStorm automatically replace all the occurrences of the selected expression (if the selected expression is found more than once in the method).
Constant syntax In this area, choose the method to define the PHP constant. The area is available only when the refactoring is invoked outside a class definition because the choice itself is relevant only in this context: extracted class constants are defined through the const keyword only.
  • define: choose this option to have PhpStorm define the constant through the define() function.
  • const: choose this option to have PhpStorm define the constant through the const keyword.

    This method preserves the approach accepted in PHP version 5.3.0. Note that such constants are defined during compilation therefore they should be declared at the top-level scope but not inside functions, loops or if statements.

Visibility

In this area, choose the visibility scope (access level modifier) of the extracted constant. If you leave the default value selected, the constant will be implicitly defined as public without any modifier applied to it. Otherwise, you can choose the appropriate option to explicitly mark the constant as public, private, or protected.

The area is available only when language level is set to PHP language version 7.1 and later. You can specify the PHP language level on the PHP page (File | Settings | Languages and Frameworks | PHP for Windows and Linux or PhpStorm | Preferences | Languages and Frameworks | PHP for macOS).

Last modified: 27 July 2018

See Also