User Guide > Tasks > Using Refactoring > Renaming Elements

Renaming Elements

This procedure describes how to rename a PHP element and ensure that all references to that element are updated.

All PHP elements can be renamed and refactored from PHP Explorer view. The following is a list of applicable PHP elements:

Note:

Ensure that you save any changes to the file before applying the refactoring feature.

Elements can either be renamed from within the editor itself if the In-place refactoring feature is activated (will not display a preview of changes) or from the Rename Element dialog.

Renaming Elements within the Editor

 

 

Instructions on how to complete a procedure

To rename an element within the editor:

  1. Ensure the 'Rename in editor without dialog' checkbox is marked in the Code Refactor Preferences page (accessible from Window | Preferences | PHP | Code Refactor).

  2. In the editor, place your cursor on the element to be renamed.

  3. From the menu bar select Refactor | Rename -or- right-click and select Refactor | Rename -or- press Alt-Shift-R.
    All occurrences of the element are put in a frame and the Refactor popup is displayed.

 

  1. Type the new element name in the box.
    All occurrences of the element name are automatically updated.

Note:

To preview the changes before applying them, click the arrow in the right-hand corner of the Refactor popup and select Preview.

  1. Click Enter to apply the refactoring.
    A  dialog is displayed prompting you to save the file before the refactoring is applied.

  2. Mark the 'Always save all modified resources automatically prior to refactoring' checkbox so that the dialog will not be displayed again.

  3. Click OK.

The element will be renamed and all instances where that element is referenced will be updated to reflect the changes.

Renaming Elements through the Refactor Dialog

 

 

Instructions on how to complete a procedure

To rename an element through the Refactor dialog:

  1. Ensure the 'Rename in editor without dialog' checkbox is unmarked in the Code Refactor Preferences page (accessible from Window | Preferences | PHP | Code Refactor).

  2. In the editor, place your cursor on the element to be renamed or select it in the PHP Explorer.

  3. From the menu bar select Refactor | Rename -or- right-click and select Refactor | Rename -or- press Alt-Shift-R
    The Rename dialog box will be displayed. The name of the dialog will be dependent on the element type.

Rename Global Variable

  1. Enter the element's new name. You must enter a valid name for the required element - i.e. one that starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

  2. Check the "Update textual occurrences in comments and strings" box if you want the element's name to be updated in all comments and strings where it is referenced.
    This will force you to preview the changes before applying them.

  3. Click OK to apply your changes or click Preview if you want to see a preview of the changes that this refactoring will create.

  4. If you clicked preview a preview window will open with a changes tree showing all the changes which will be made to reflect the rename of the element.
    The changes will be listed according to the context within which they appear. You can therefore expand the nodes to see all changes within particular files, classes or functions.

  5. Use the Next / Previous Change arrows to scroll through all possible changes.
    Unmarking the checkboxes next to the changes will cause those changes not to take effect.

Rename Global Variable changes tree

Note that if changes will be made in other files which reference the element being refactored, the changes will also be listed here under the file name.

  1. The changes to be applied will be displayed in the bottom pane.
    You can scroll through the different changes using the scrolling arrows:

  • Next / Previous Difference scrolling arrows - Scroll through changes to be applied within the element selected in the top pane.

  • Next / Previous Change scrolling arrows  - Scroll through all changes to be applied. If you unmarked changes in the top pane, these will not be displayed when using these arrows.

  1. Once you are satisfied with the changes, click OK.

The element will be renamed and all instances where that element is referenced will be updated to reflect the changes.

 

 

Related Links:

Refactoring

Using Refactoring

Renaming Files

Organizing Includes

Refactor Menu

 

 

©1999-2013 Zend Technologies LTD. All rights reserved.