“Introduce Constant” refactoring for PHP
The “Introduce Constant” refactoring is very similar to the “Introduce Variable” refactoring – it creates a constant which holds the selected expression as the value and replaces it occurrences by reference to this newly created constant.
In order to invoke the refactoring, select an expression to be replaced with a constant or place the caret before such expression and press Ctrl+Alt+C(for Windows) or Cmd+Opt+C(for Mac).
The result of the refactoring depends on the context it is invoked in. If the refactoring is invoked inside a class, the constant will be introduced in the class. Otherwise, the constant will be introduced in the current file/namespace.
You can also introduce constants in string literals
Develop with pleasure!
Subscribe to Blog updates
PhpStorm 2023.3 Is Now Available
Explore the new features in PhpStorm 2023.3: support for PHP 8.3, the Pest test framework, improvements for Symfony projects and AI Assistant.
PhpStorm Now Supports PHP 8.3
PhpStorm now provides full support for PHP 8.3 feature: the new `#[Override]` attribute and `json_validate()` function, and more!