Search code examples
phpstorm

Why is my function declaration wrapping to 2 lines?


I am using PHPStorm 7. When I write the following code,

public function ()
{

}

and then reformat it, it outputs the following format:

public
function ()
{

}

Why does the word 'function' wrap to a second line? I tried turning and off every setting in the PHP code style settings dialog with no success. Where can I turn that off?


Solution

  • There is a setting called 'Wrap after modifier list' that puts the 'function' keyword on a new line. You probably have that checked.

    As it's name suggests, it 'wraps' after the modifier list. Modifiers are keywords such as public/protected/private, abstract, final, static etc. So

    final public static function bar()
    

    becomes

    final public static
    function bar()
    

    Note that classes are affected by this, too:

    abstract class Foo
    

    becomes

    abstract
    class Foo
    

    The setting should be in the 'Wrapping and Braces' tab (under Settings > Code Style > PHP), in the bottom of the list. Unchecking it should solve your problems.