An Oracle blog about NetBeans for PHP

Formatting - Braces - Update

The position of braces in PHP code can be set up in the PHP formatting setting, category Braces(select item Braces in the Category combo box). It's possible to set up separately position of the brace after class declaration, function or method declaration and for other statements.

There are three values -  Same Line, New Line and Preserve Existing  that can be set to. The default value is Same Line.

Join the discussion

Comments ( 23 )
  • guest Sunday, February 7, 2010

    Pretty much all one needs. Thanks ;)

  • Xantiva Sunday, February 7, 2010

    Thanks, that looks very good. (You see, I found your edited post. ;) )

  • foo Sunday, February 7, 2010

    Yes! This is perfect! I'm personally a fan of new line on class and functions, same line on others.

  • guest Sunday, February 7, 2010

    good work!

  • Koen Monday, February 8, 2010

    Looks very good, thanks!!

  • Jasmo Monday, February 8, 2010

    Have you fixed this indentation of first brace? In 6.8 if you have braces on the next line, this happens if you write if($foo), press enter, press { and press enter:




    (... is just a tab placeholder)

    It should be




  • Ladislav Prskavec Monday, February 8, 2010

    This is better. I have problem with bracket at else

    in your example:

    if () {


    else {


    and i think better will be:

    if () {

    } else {


    Is possible correct this ?

  • Petr Pisl Monday, February 8, 2010

    To Jasmo: It should work now.

    To Ladislav: I will try to add as new option for new lines category.

  • Tom Monday, February 8, 2010

    Well, this is good news. Finally NetBeans does support the PEAR coding standard! :)

    However: the coding standard in our company demands that some structures ("if" and "switch") have the opening brace in the same line, while others ("while", "for" and "try") have the brace on the following line.

    But I think that keeping the setting to "preserve existing" will do.

  • Jozef Monday, February 8, 2010

    @Tom: IMHO your company has very strange "coding standards".

  • Bruce Ingalls Monday, February 8, 2010


    It will be even nicer, to align coding style, with CodeSniff checking, such as


    In particular, default NetBeans indentation sniffs as an invalid style :(

  • Mark Tuesday, February 9, 2010

    Every new feature in this blog i reply with always the same issue. What netbeans lack is a support for svn password via ssh. I mean when we have to access an svn repository over ssh the program always prompt for the password. This issue is old and it make svn over ssh unusable

  • Petr Pisl Tuesday, February 9, 2010

    To Mark: I can not help you directly. I don't develop the svn support. I have talked with the guys about this, but I don't have such power as you, as user. Enter a new bug against the svn support. Push the svn support developers to fix it. I'm sure that these guys doesn't read this blog.

  • Tom Tuesday, February 9, 2010

    @Jozef I don't care if they are "strange". Most companies don't even have any such thing as a standard.

    Every developer of course has an own idea of what "nice" code should look like. Take 10 developers and you possible will get 12 opinions of how to indent code, indent follow-up lines, maximum numbers of characters per line, format comments, indent braces, use of exceptions, or even how to comment SVN updates.

    Note that others, like the PEAR coding standard, even demand a specific order of PHPDoc elements and a blank line after certain parts of your comment, or certain @-rules. PEAR also expects single-line comments with exactly 3 opening curly opening and closing braces around each function declaration. Where the function name and parameter list is copied to the opening comment.

    Now this is what I would call "strange". However I believe it is some setting for a specific code editor, which needs these for code-folding. One day some core developer may have decided to use this specific editor and filed a standard that required all later developers to support it - forever.

    Zend, for example, has a coding standard as well. This standard sometimes requires the opening bracket for a function body on a new line but for some cases require it to be on the same line, when there is a line break within the function head.

    The same applies to if-blocks. They also demand that you MUST provide a @link block in your comments. So you MUST provide a unique URL for each package - even if it is not valid.

    So: I guess we are really good off with our coding standard. ;)

  • Jozef Tuesday, February 9, 2010

    @Tom: Thank you for "strange" examples. I am happy we have adopted the Sun Java coding standards for PHP projects too, because our primary job is Java ;-) http://java.sun.com/docs/codeconv/

  • Tom Wednesday, February 10, 2010

    @jozef Yes. Actually our coding standard is based on the Java coding standard rather than using PEAR or Zend.

    We also adopted the naming convention and e.g. the "fall through" comment for switch-statements.

    However we introduced some minor modifications as it doesn't always seem to "fit" as well for PHP.

    For example: the Java-style switch-statement does not follow the code-indention rules.

    The Java naming convention allows pure verbs as function names. So "read()" would be fine for Java -> read what? Apples? Books? Files?

    We also don't use java-style pre-formatted DocBlocks, since PHPDoc has a tag for that.

    Also PHP does not have the same kind of variable shadowing that Java does. So we require that you unset() all loop-vars after the loop and that you check that they are not in use before you enter the loop. You simply don't need to do this in Java, so it's missing!

    There are more of those examples.

    In other words: you can't simply "copy" the Java coding-style to PHP. It won't work as well.

  • Symfony Developer Wednesday, February 10, 2010

    Offtopic: I think we need a post explaining the future of Netbeans and PHP in the hands of Oracle.


  • Marco Thursday, February 11, 2010


    While this new feature is great, I haven't found a way to do this formatting:

    function whatever()




    if (...)








    Is there a way to edit some template or something to achieve that?

    Thank you.

  • Petr Pisl Thursday, February 11, 2010

    To Marco: Unfortunately there is not a way how to do it now. I can extend the list of values with New Line Indented and probably New Line Half Indented?

  • Marco Wednesday, February 17, 2010

    Thanks Petr, maybe that would work, I will certainly try it.

  • Brandon Harvey Monday, November 15, 2010

    An option for "new line (fully) indented" would be great indeed, as our company coding style requires it. Any progress on this? Thanks!

  • Petr Pisl Thursday, November 18, 2010

    To Brandon Harvey: Could you just file new issue in our bugzilla. It shouldn't be hard to implement this. Thanks.

  • Brandon Harvey Thursday, November 18, 2010

    OK, done! Bug 192127. Thanks...

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.