PhpStorm 2016.3 Help

PHP-Specific Coding Assistance

On this page:

Converting long array syntax to short

Suppose you have an array declared in the traditional literal style:

<?php $a=[array(1,[[1 => array(1,1=>[1])],1])];
You can detect all the traditional literal style declarations in your code and convert them into short style:

  1. On the main menu, choose Code | Run Inspection by Name, or press Ctrl+Shift+Alt+I.
  2. In the pop-up frame that opens, start typing the inspection name Traditional syntax array literal. As you type, the suggestion list shrinks to show the matching inspection only. Press ?. The Specify Inspection Scope dialog box opens.
  3. In the Inspection scope area, specify which files should be inspected.
    • To have the source code of the entire project inspected, select the Whole Project option.
    • If you are using version control integration, you can choose to only inspect uncommitted files.
    • To run an inspection for the currently opened file, or the file(s)/folder(s) selected in the Project view, select the File/Module <name> option.
    • To apply inspect code in a specific scope, select the Custom scope option, then choose the desired scope from the drop-down list or click the Browse button /help/img/idea/2016.3/browseButton.png and configure a new scope in the Scopes dialog box.
  4. To have test source files inspected too, select the Include test sources check box.
  5. Click OK to run the inspection.
  6. The Inspection Tool Window opens showing the list of files where the traditional literal style declarations have been detected:
    ps_coding_assistance_conver_array_to_short.png
    Click Convert array syntax to short. The code is updated as follows:
    <?php $a=[ [ 1, [ [ 1 => [ 1, 1=>[ 1] ] ], 1] ] ];

Using live templates for smart completion of parameters in function calls

PhpStorm has an “automatic” live template that provides completion lists for the parameters passed into functions, methods, or class constructors.

  • To activate this functionality:
    1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X. Expand the Editor node, and then click Smart Keys under General.
    2. On the Smart Keys page that opens, select the Enable smart function parameters completion check box in the PHP area.
  • To invoke the magic live template, type the params keyword as the first parameter in the call of the function, method, or class:
    ps_smart_parameter_completion_step_1.png
    PhpStorm displays a live template where the parameters are automatically completed with the variable names defined in the function declaration. To move to the next parameter, press Enter or Tab. To move to the previous parameter, press Shift+Tab.

    The completion list contains variables from a local scope in the next order: with the same type, with a similar name, defined nearby. You can always switch to the usual completion mode by pressing Ctrl+Space or just typing anything which is not in the list. Variables with similar names are inserted automatically.

See Also

Last modified: 1 December 2016