“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!

Comments below can no longer be edited.

3 Responses to “Introduce Constant” refactoring for PHP

  1. OZ says:

    March 1, 2011

    Has used today – very handy 🙂

  2. ragtek says:

    March 7, 2011

    The help doesn’t work.

    When clicking on the help button
    http://blogs.jetbrains.com/webide/wp-content/uploads/2011/02/introduce_constant_1_before.png i’m getting this error:

    Help topic “refactoring.introduceConstant” not found

  3. Nikolay Matveev says:

    March 7, 2011

    Thanks for report! We have took steps.