4

Let us take this example from PHP.net

    <?php
    if ($a > $b) 
    {
         echo "a is größer als b";
    } 
    else if ($a == $b) 
    {
         echo "a ist gleich groß wie b";
    } 
    else 
    {
         echo "a ist kleiner als b";
    }
    ?>

Pretty basic stuff. STRG or CTRL + ALT + l reformats the code, but in a way that is rather strange:

    if ( $a > $b )
    {
        echo "a is größer als b";
    }
    else
    {
        if ( $a == $b )
        {
            echo "a ist gleich groß wie b";
        }
        else
        {
            echo "a ist kleiner als b";
        }
    }

There is no template or anything that I would know of that could trigger this. Nevertheless, it is a nuisance to have the code changed in such a kind of way.

The question is: how can I prevent PhpStorm from doing this. It appears only in since the latest update of the software (PhpStorm 2016.2.2) not in earlier ones.

The version of PhpStorm is

  • PhpStorm 2016.2.2
  • Build #PS-162.2380.11, built on October 24, 2016
  • JRE: 1.8.0_112-release-287-b3 amd64
  • JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
3
  • what kind of formatting you want? Commented Nov 3, 2016 at 6:34
  • That the else if construct is not being broken apart in such a manner. The thing is that elseif remains the same after a code refactoring, while else if does not. This is something that has changed with the latest update Commented Nov 3, 2016 at 6:40
  • 1
    I'm confused by this being the default behavior and that I need 'special treatment' for it to leave my code alone. Very silly. Commented Nov 20, 2017 at 4:38

1 Answer 1

12

Go to File > Settings > Editor > Code Style > PHP > Wrapping and Braces tab and check "Special 'else if' treatment"

Sign up to request clarification or add additional context in comments.

1 Comment

That appears to be new. I must have overlooked it. Sadly, it does not reverse the mess that it had created in the first place. As this had only been at one point in my code, not much harm had been done. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.