New Code Style Options in PhpStorm 2017.1

PhpStorm 2017.1 brings a smorgasbord of new code style settings so you can get your code looking just how you like it.

We all know that having your code formatted the right way is important – after all, the Tabs vs Spaces debate has divided many communities (it’s spaces for what it’s worth). PhpStorm 2017.1 gives you some new code style options so you can get your code looking just so. Most of these changes were requested by users on our issue tracker, YouTrack.

We’ve added a new option in code styles which will remove the () from a new call when you don’t pass any constructor arguments. You can find the setting under Settings | Code Style | PHP | Wrapping and Braces | Function/constructor call arguments | Place ‘()’ for constructor.

To make sure you consistently use elseif or else if (whichever you prefer),  you can configure PhpStorm to format elseif to else if (or vice versa) using Code Style | PHP | Other | Convert else if/elseif to: and then selecting the format you want to use.

Something that’s been annoying me slightly is PhpStorm not letting me enforce a new line between <?php and the namespace declaration. You can find the setting under Code Style | PHP | Blank Lines | Before namespace. In writing this very blog post we also realised that this won’t solve the problem for everyone because of PHP 7’s declare(strict_types=1) declaration being the first line in a file – we’ve opened a ticket for that so look out for it in the future.

And speaking about PHP 7, there’s a new feature to enforce spaces around the equals sign in a declare(strict_types=1) declaration. The proposed PSR-12 standard does say that these declarations should have no whitespace in them, but if your own coding style differs, you can enforce the spaces using  Code Style | PHP | Spaces | Around Operators | Assignment in declare statement.

We’re trying to make sure your code style looks exactly how you want it to, so let us know what you think – or if we’re missing anything.

– Gary & The PhpStorm Team


About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter. Bookmark the permalink.
  • Clint Priest

    These are great additions, you guys are truly awesome. I do wish that proper tab support were available though, specifically for formatting/alignment. Using tabs whenever possible and a space or two to get the last stretch. It’s been a feature request for many years.

    Also, the latest Developer Survey 2017 from Stack Overflow ( shows that tabs are preferred by the majority of developers over spaces.

    • Vladimir Luchansky

      Code style preferences are usually different with each team. And PSR is still about spaces, not tabs: .
      Would be great if you could add your thoughts on this feature request into YouTrack so the team could see them and think about the implementation.

  • Geoff Kendall

    Hi Gary, thanks for your work on this. It could be a really great feature, but it’s not quite getting across the line for me. I have two very similar sites – a dev site and the live site. When I go to compare the public_html for each site, dozens of files are flagged as having differences even though (apart from newlines and whitespace) they are the same. So I thought I’d reformat all the files to a standard, have identical looking code for equivalent pages, no longer be seeing files that are effectively the same being flagged as different. Problem is that the formatting to a standard doesn’t seem to remove whitespace well enough to leave equivalent files looking the same. It would be awesome if reformatting similar files left them with identical layout, so those files wouldn’t have any differences ‘that can be ignored’, just absolutely no differences and hence no appearance in the top half of the compare window. Happy to chat on the phone if that’s any use – 01347 821928 UK

    • Vladimir Luchansky

      This situation is pretty weird, we don’t have any reports about whitespace removal being not the same for equibalent files. Feel free to contact our team via PhpStorm > Help > New Support Request and we’ll be happy to assist with this.

      • Geoff Kendall

        Hi Vladimir, thanks for your reply. It isn’t that the whitespace removal is different for different files, it’s that if the files are different because they have different spaces and newlines, they will still be different after reformatting. Ideally, the default IDE reformatting would make the two files absolutely identical. At present, comparing my dev site to the live site will show dozens of files as different – but only because the whitespaces are different. I was hoping to reformat both sites to the same standard and so that only the ‘really different’ files would then show in the compare window.

        • Eugene Morozov

          Geoff, what if you disable Settings | Editor | Code Style | PHP | Wrapping and Braces | Keep on reformatting | Line Breaks, does reformatting bring the files to the same state?

          • Geoff Kendall

            Thanks Eugene, I’ll try that and report back :-)

        • Vladimir Luchansky

          In the side-by-side viewer of Diff window there’s an option to ignore whitespaces and blank lines – – is it not suitable?

          • Geoff Kendall

            Hi Vladimir, unless I’ve missed something, you only see that the differences can be ignored by selecting the ‘unequal’ pair of files one after the other. That means stepping through several dozen files one at a time. It would be great if either a) Ideally, ‘otherwise identical’ files with whitespace and empty line differences could be made absolutely identical with automatic code formatting or b) The dozens of files with whitespace differences that are being ignored are removed from the list of files shown as ‘unequal ‘ – only the file pairings with differences that are not being ignored would be shown.
            Maybe (amd now I’m dreaming..!) both a) and b)?

          • Vladimir Luchansky

            Well, there are options to trim whitespaces and sort out the blank lines via configuring the code style and then reformatting the files from the remote side but this would require downloading them all, reformatting and then uploading back.
            The issue for b) is – please vote for it.