Code Style. PHP
Use this page to configure formatting options for PHP files. View the result in the Preview pane on the right.
Click this link to choose the base for the current language default code style from the pop-up list, that appears. The list contains two options:
- Language: choose this option to inherit the coding style settings from another language. Select the source language from the list, that opens. So doing, only the settings that are applicable to the current language are taken. All the other settings are not affected.
- Predefined code style: choose this option to use the coding standards defined for a specific framework. Select one of the following frameworks from the list:
This link appears in the upper-right corner of the language-specific code style page, when applicable.
Click Reset to discard changes and return to the initial set of code style settings.
Tabs and Indents
|Use tab character|| |
|Smart tabs|| |
The Smart Tabs checkbox is available if the Use Tab Character checkbox is selected.
|Tab size||In this text box, specify the number of spaces included in a tab.|
|Indent||In this text box, specify the number of spaces (or tabs if the Use Tab Character checkbox is selected) to be inserted for each indent level.|
|Continuation indent||In this text box, specify the number of spaces (or tabs if the Use Tab Character checkbox is selected) to be inserted between the elements of an array, in expressions, method declarations and method calls.|
|Keep indents on empty lines||If this checkbox is selected, then IntelliJ IDEA will keep indents on the empty lines as if they contained some code.|
If this checkbox is cleared, IntelliJ IDEA will delete the tab characters and spaces.
PHP-specific formatting settings for Spaces
Select or clear the checkboxes to have spaces inserted, not inserted, or removed in the following PHP contexts:
|Before Parentheses|| |
|Around Operators|| |
|Before Left Brace|| |
Select the checkboxes in this section to have spaces automatically inserted within the selected code code constructs.
| In Ternary Operator (|| Select the checkboxes in this section to have spaces automatically inserted before and after |
|Other|| Select the checkboxes in this section to have spaces automatically inserted before and after commas, semicolons, unary NOT operators (|
PHP-specific formatting settings for Wrapping and Braces
|Braces placement|| In this section, choose the position for opening braces in declarations of namespaces, classes, and functions, in loops, and in other constructions. Choose the required position from the drop-down list, the available options are: |
|Extends/implements list|| In this section, configure wrapping and subsequent alignment of extend and implements lists: |
|Extends/implements keyword|| In this section, configure wrapping for the extends and implements keywords in class declarations. |
If you choose the Do not wrap option, no wrapping will be applied, if you choose Wrap if long or Wrap always, each keyword and each item in an extends or implements list will be displayed on a new line:
|Function declaration parameters|| In this area, configure formatting in declarations of functions and methods. |
|Chained method calls|| In this section, configure wrapping and subsequent alignment of chained calls. |
|Assignment statement|| In this section, configure wrapping and subsequent alignment in assignment statements. |
|Class field/constant groups|| In this section, configure wrapping and subsequent alignment within lists of class properties (fields) or class constants. |
|Array initializer|| In this section, configure wrapping and subsequent alignment in array declarations. |
|Modifier list|| |
Use this tab to define where and how many blank lines you want IntelliJ IDEA to retain and insert in your code after reformatting. For each type of location, specify the number of blank lines to be inserted. The results are displayed in the Preview pane.
|Keep Maximum Blank Lines||In this area, specify the number of blank lines to be kept after reformatting in the specified locations.|
|Minimum Blank Lines||In the text boxes in this area, specify the number of blank lines to be present in the specified locations.|
|Align parameter names||Select this checkbox to have the |
|Keep blank lines||Select this checkbox to suppress removing blank lines automatically.|
|Blank lines around parameters||Select this checkbox to have a blank line inserted above and below the section with |
|Blank line before the first tag||Select this checkbox to have an blank line inserted above the first PHPDoc tag.|
|Align tag comments||Select this checkbox to have the |
|Wrap long lines||Select this checkbox to have the text that exceeds the right margin wrapped to the next line.|
|Generated Doc Blocks||In this area, configure the code style to be applied within generated PHP documentation blocks, see PHPDoc Comments. |
In this tab, configure the code style to be applied when performing automatic code conversion.
|Convert True/False constants to||Select the desired option to have the |
|Convert Null constant to||Select the desired option to have the |
|Convert else if/elseif||Select the desired option to have |
|Array declaration style|| |
|Variable Naming Style||Select the desired option to have the generated variables displayed uniformly in Mixed case, camelCase, or snake_case.|
|Fields Default Visibility||Select the desired option to automatically prefix the generated class fields with private, protected, or public visibility modifiers.|
|Comment Code||In this area, configure the code style options to be applied to comments. |
In this tab, define a set of rules to rearrange your PHP code according to your preferences.
|Grouping Rules||Use this area to set the grouping rules. |
|Matching rules||Use this area to define elements order as a list of rules, where every rule has a set of matches such as modifier or type. |
|Empty rule||Use this area to create a new matching rule or edit an existing one. You can select from the following filters: |
|This icon appears when you select Order by Name from the Order list. The icon indicates that the items in this rule are sorted alphabetically.|