Features PhpStorm

New PHP formatting options in PhpStorm 3.0

Probably some of you have already noticed the changes in PHP code style settings. Putting the new UI look aside, I’d like to focus on new options and briefly explain their meaning and functionality. I hope you find them useful for making your code look more readable and closer to coding standards like PEAR or Zend.

PhpDoc Formatting (Settings|CodeStyle|PHP|PHP Doc)

There is a number of options which allow you to control the look of your PHP doc comments on reformatting:

  • Align parameter names
    Aligns the parameters prefixed with dollar ‘$’ sign.
  • Keep blank lines
    Tells if the blank lines (either put manually or inserted on previous reformatting) should be kept. Unchecking the flag will remove any blank lines which are not required by other options. Note: blank line here of course means an empty PHDoc line prefixed with a star ‘*’ character.
  • Blank lines around parameters
    Inserts blank lines around a group of parameter descriptions each starting with @param tag.
  • Blank line before the first tag
    Separates a description from the rest of PHPDoc. Note that if “Blank lines around parameters” is checked and the first tag is @param, the flag has no effect because there is already a blank line inserted by another option.
  • Align tag comments
    Aligns comments of @param tags and other tags. The two groups of tags (@param and other) are handled separately. Tags may have multiline comments in which case the whole comment will be aligned up to another tag or a blank line. Since blank lines appear meaningful for the alignment, it makes sense to keep them (make sure the “Keep blank lines” box is checked).

Code Alignments (Settings|Code Style|PHP|Other)

  • Align key-value pairs
    If checked, tells the formatter to align key=>value pairs on hash ‘=>’ sign. That’s the options you would most likely to check right now.
  • Align consecutive assignments
    If you have a group of assignments following each other without any gaps, they will be aligned on equals ‘=’ sign. By a gap I mean either a blank line, a comment or any other operator which is not an assignment (for example, echo).

Do you miss an option or have found a bug?

In both cases you are welcome to submit a feature request or a bug report at http://youtrack.jetbrains.com. And thanks in advance for any feedback!

Comments below can no longer be edited.

9 Responses to New PHP formatting options in PhpStorm 3.0

  1. Avatar

    Bryan Green says:

    October 31, 2011

    I appreciate the Code Alignments the most. The underlying code for the formatting has matured and works well.

  2. Avatar

    Jay R. says:

    October 31, 2011

    Eek. It’s all great, except that turning on the “Blank line before first tag” option *literally* randomizes my code and throws about two dozen exceptions.

  3. Avatar

    rustam.vishnyakov says:

    November 1, 2011

    it would be great if you could report them. And even better: submit a bug with a code sample which is not handled correctly. This would very much help us to identify and solve these kind of problems.

  4. Avatar

    Alex M. says:

    November 1, 2011

    Really appreciating the parameter name alignment, was about the only thing I missed moving from Eclipse!

  5. Avatar

    Richard Hobson says:

    November 1, 2011

    Is there a nice comprehensive list of PHP Doc settings that are supported by phpStorm? I find most of the PHP Doc information to be poorly written and organized.

    I really like the idea of it but need a good reference to use while getting started.

  6. Avatar

    John says:

    November 2, 2011

    Great, but what always ticks me off is that such features are limited to only part of a program. This should work in JavaScript as well. Why make a program work differently for different parts of it?
    What if you build in a different “save” option in the menu’s for every language (PHP, HTML, JS, etc.). It’s the same thing. Formatting should work the same in all languages.

  7. Avatar

    rustam.vishnyakov says:

    November 3, 2011

    Do you mean formatting options or other, like inspections?
    We have had different requests on the subject. Some people prefer having different code styles for different languages they are working with. But anyway, you can simply copy most of the settings from one language to another unless these settings are language-specific. You can use “Copy settings from” button at the bottom of code style settings panel for that. Unfortunately this doesn’t apply to JS doc, partly because different frameworks use their own documentation style.

  8. Avatar

    Andreas says:

    November 9, 2011

    The alignment of consecutive assignments does not work for class constants. Would be nice if this would be possible too.

Discover more