Code Style. PHP
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.
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.
Item | Description |
---|---|
Indent as template language unless PHP-only |
|
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 checkboxes 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 checkboxes in this section to have spaces automatically inserted before and after ? , before and after : , and between ? and : in ternary (conditional) operators. |
Other | Select the checkboxes 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.
Item | Description |
---|---|
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. These settings do not influence the number of blank lines before the first and after the last item. |
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 checkbox to have the &<paramname> elements aligned. |
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 @param tags. |
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 description elements aligned. |
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.
|
@throws Tag Analysis |
|
Other
Item | Description |
---|---|
Indent code in PHP tags | Select this checkbox to have the code enclosed in <?php> tags indented against the opening <?php tag. |
Convert True/False constants to upper case | Select this checkbox to have the true and false constants displayed in the upper case. |
Convert Null constant to upper case | Select this checkbox to have the null constant displayed in the upper case. |
Blank line before return statement | Select this checkbox 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. |