An Oracle blog about NetBeans for PHP

Formatting - Braces

Based on the comments under this post the options for placing braces were changed. So this post is not relevant anymore and new information you can find here.

When you select PHP language in the formatting setting then in Category combo box you can select category Braces. The panel for this category contains only one combo box, where you can define the position of braces. There are three values -  Same Line, New Line and Preserve Existing. The default value is Same Line. See the picture.

 I'm not sure whether this one option is sufficient. Does someone have a requirement to offer more options for the braces? For example the Java formatting has options that allow to set different behavior for class declaration, methods declaration and other cases. Also it allows to set that  braces are indented on the new line.

Join the discussion

Comments ( 12 )
  • e.s.t Friday, February 5, 2010

    That is already cool!

    As about options, would it be possible to have fourth option called 'PEAR Standard' (ect.) and achieve formatting like this:


    So it is like new line for classes and functions, and same line for control structures.

  • Petr Pisl Friday, February 5, 2010

    To e.s.t: thanks for the link. From this is clear that I will have to make more options for this category.

  • Maghiel Dijksman Friday, February 5, 2010

    Another link for you


    It's largely based on the PEAR standard

  • matera.ttp Friday, February 5, 2010

    Great feature.

    +1 for pear standard (new line for functions and classes and same line for other blocks)

  • Joel Simpson Friday, February 5, 2010

    +1 for Zend (and other standards as well).

    Certainly, having the same options that Java code formatting provides would be ideal. :)

  • Ladislav Prskavec Friday, February 5, 2010

    I see big problem with use options new line. Classes and function are ok, but if, else, switch, try are in some line better.

    You can add options as in spaces for different statements can use different braces.

    +1 for Zend

  • ladenise Friday, February 5, 2010

    Hello all

    Great feature !

    I think it's important for the PHP industrialisation that you had PEAR and Zend coding standards.

    I don't really know NetBeans but I'm working on it... This could be really awesome to be abble to couple the selected coding standards with PHP_CodeSniffer auto checking while coding. What do you think

    Hope my frenchy english is clear enough

  • Martin Vrkljan Saturday, February 6, 2010

    Nice feature!

    It would be nice to include options for class declarations and method declarations/calls, too. Would adding options for spaces between class/method names and braces be possible as well?

  • Jeremy Clarke Saturday, February 6, 2010

    These options are satisfying for me!

    On a related note I'd LOVE to see support for endif style control structures in netbeans. I find it much more readable than braces and it seems like it would be simple enough to make it work like HTML tag prediction, offering the closing statement after the opener is typed and highlighting the matching keyword when the cursor is in it's partner (ie highlight foreach when endforeach is clicked)

    thanks and good luck with 6.9!

  • Maghiel Dijksman Saturday, February 6, 2010

    I agree with Jeremy Clarke,

    by example in views it's quite common to use that structure.

  • Andrew Higginson Wednesday, March 3, 2010

    Very impressed so far with the new formatting features. Just a few things that I've noticed...

    When formatting an interface function e.g,

    function test();

    The source formatting becomes...

    function test()


    Not sure why this is? Also, else/elseif statements don't get moved up a line if I specify other braces to be on the same line. So every time I do formatting, I need to go through and look for else statements and change from...


    else {

    to } else {

    Also try formatting an empty class definition, for some reason the formatting removes the first brace of the class body and the ? in the ending php tag of the file.

    Thanks very much, and if I've posted this in the wrong place, please let me know.


  • Andrew Higginson Thursday, March 4, 2010

    Probably worth mentioning that my above comment was in relation to the new PHP formatting options.



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