PHP Question

PHPStorm Code Refactoring elseif PHP

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


qkr qkr
Answer

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

Comments