PhpStorm 2017.2 Help

Change Signature Dialog

Refactor | Change Signature
Ctrl+F6

Use the Change Signature dialog to perform the Change Signature refactoring in the PHP context.

Use the available controls to make changes to the function signature. Specify how the function calls should be handled. Optionally, select the calling functions that the added parameters and exceptions (if any) should be propagated to.

Click Refactor to perform the refactoring right away. Click Preview to see the potential changes prior to actually performing the refactoring. (These will be shown in the Find tool window.)

ItemDescription
VisibilitySelect the method visibility scope (access level modifier) from the list.
Return typeUse this field to modify the function return type.

Code completion (Ctrl+Space) is available in this field, and also in other fields used for specifying the types.

Setting the function return type is only possible in 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).

NameUse this field to modify the function name.
ParametersSee the description of the Parameters area.
Signature PreviewIn this area, the current function signature is shown. (The information in this area is synchronized with the changes you are making to the function signature.)

Parameters area

Use the Parameters area to manage the function parameters.

The available controls let you add new parameters, remove the existing ones, reorder the parameters and also propagate new parameters to the calling functions (see the descriptions that follow).

In addition to that, you can change the names of the existing parameters.

To start editing a parameter, just click it. Alternatively, use the Up and Down arrow keys to navigate to the parameter of interest and Enter to start modifying it.

ItemTooltip and shortcutDescription
newAdd
Alt+Insert
Use this icon or shortcut to start adding a new parameter.

Specify the name and default value in the corresponding fields. (The default parameter value is the value (or the expression) to be passed to the function in the function calls.)

You can also propagate the parameters you have added to the calling functions.

deleteRemove
Alt+Delete
Use this icon or shortcut to delete the selected parameter.
arrowUpUp
Alt+Up
Use this icon or shortcut to move the selected parameter one line up in the list of parameters.
arrowDownDown
Alt+Down
Use this icon or shortcut to move the selected parameter one line down in the list of parameters.
propagateParameters Propagate Parameters
Alt+G
Use this icon or shortcut to propagate the added parameters to the calling functions.

You can propagate the changes made to the function parameters to any function that directly or indirectly calls the function whose signature you are changing.

(There may be the functions that call the current function. These, in their turn, may be called by other functions. You can propagate the changes to any of the methods in such sequences.)

In the dialog that opens, select the functions you want the changes to be propagated to.

Note that only the selected calling functions and the function calls within them will be affected. That is, the default values will be added into other function calls.

Create and initialize class propertiesThe check box is available only in the PHP context when the Change signature refactoring is invoked from the constructor of a class.
  • When this check box is selected, the newly added parameter is initialized as a field. PhpStorm creates a protected field with the same name as this parameter and adds a line with the following assignment:
    $this-><parameter_name> = $<parameter_name>;
  • When the check box is cleared, a parameter is added without initialization.

For example, you have the following constructor:

class ChangeSignatureNewParam { function __construct() { $a = "Constructor in ChangeSignatureNewParam"; print $a; } }
If you invoke the Change signature refactoring from the __construct() method and add a new $q parameter, the result will depend on whether you select or clear the Create and initialize class properties check box:

  • The Create and initialize class properties check box is selected:

    class ChangeSignatureNewParam { private $q; function __construct($q) { $a = "Constructor in ChangeSignatureNewParam"; print $a; $this->q = $q; } }
  • The Create and initialize class properties check box is cleared:

    class ChangeSignatureNewParam { function __construct($q) { $a = "Constructor in ChangeSignatureNewParam"; print $a; } }
Last modified: 28 November 2017

See Also