Code Style. PHP
for Windows and Linux
for macOS
Ctrl+Alt+S
Use this page to configure formatting options for PHP files. View the result in the Preview pane on the right.
On this page:
- Set from...
- PHP-specific formatting settings for Tabs and Indents
- PHP-specific formatting settings for Spaces
- PHP-specific formatting settings for Wrapping and Braces
- Blank lines
- PHPDoc
- Other
- Arrangement
Set from...
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:
- PEAR
- Zend
- Symfony2. PhpStorm supports the official Symfony2 code style for Twig and automatically inserts one space after an opening pair of curvy braces and before a closing pair of curvy braces in Twig templates:
{{ some_variable }}
. - PSR1/PSR2
- WordPress
- Drupal
- Joomla!
- JavaScript Standard Style
- Google JavaScript Style Guide
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.
PHP-specific formatting settings for Tabs and Indents
See Common Code Style Options: Tabs and Indents for the settings that are common for all languages.
PHP-specific formatting settings for Spaces
See Common Code Style Options: Spaces for the settings that are common for all languages.
Select or clear the check boxes to have spaces inserted, not inserted, or removed in the following PHP contexts:
Item | Description |
---|---|
Before Parentheses |
|
Around Operators |
|
Before Left Brace |
|
In Ternary Operator (?: ) | Select the check boxes in this section to have spaces automatically inserted before and after ? , before and after : , and between ? and : in ternary (conditional) operators. |
Other | Select the check boxes in this section to have spaces automatically inserted before and after commas, semicolons, unary NOT operators (! ), and after type casts.
|
PHP-specific formatting settings for Wrapping and Braces
See Common Code Style Options: Wrapping and Braces for the settings that are common for all languages.
Item | Description |
---|---|
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: abstract class Foo
extends
Class1
implements
Class2,
Class8 {
} |
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 |
Blank lines
Use this tab to define where and how many blank lines you want PhpStorm 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.
PHPDoc
In this tab, configure the code style to be applied inside PHPDoc comments. Learn more about documenting PHP code at PHPDoc Comments.
Item | Description |
---|---|
Align parameter names | Select this check box to have the &<paramname> elements aligned. |
Keep blank lines | Select this check box to suppress removing blank lines automatically. |
Blank lines around parameters | Select this check box to have a blank line inserted above and below the section with @param tags. |
Blank line before the first tag | Select this check box to have an blank line inserted above the first PHPDoc tag. |
Align tag comments | Select this check box to have the description elements aligned. |
Wrap long lines | Select this check box 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. |
@throws Tag Analysis |
|
Other
Item | Description |
---|---|
Indent code in PHP tags | Select this check box to have the code enclosed in <?php> tags indented against the opening <?php tag. |
Convert True/False constants to upper case | Select this check box to have the true and false constants displayed in the upper case. |
Convert Null constant to upper case | Select this check box to have the null constant displayed in the upper case. |
Blank line before return statement | Select this check box to have PhpStorm automatically insert a blank line before each return statement. |
Spaces around variables/expressions in brackets |
|
Code Commenting | In this area, configure the code style options to be applied to comments.
|
Array declaration style |
|
Arrangement
In this tab, define a set of rules to rearrange your PHP code according to your preferences.
Item | Description |
---|---|
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. |