问题
Intro
Im developing PHP in NetBeans IDE 7.2 (Build 201207171143)
and I love the formatting
to clean up my code in my custom format.
At the moment I work in a group with colleagues. Some of my colleagues are used to write single line statement without braces (I think this is bad practice).
Examples
What my colleagues do:
<?php
if($stackoverflow == 'Cool')
echo 'Stack Overflow is Cool!';
?>
What I want when I format the code.
<?php
if($stackoverflow == 'Cool') {
echo 'Stack Overflow is Cool!';
}
?>
Question
So what I am looking for is the setting to achieve this. I can find every other setting to have nice braces.
Tools -> Options -> Editor -> Formatting -> PHP
WhatHaveITried
I have found this but I think this isn't the way for what I want to achieve since he talks about macros.
Could someone help me with this?
回答1:
I am not sure if u have find the solution or not
Tools -> Options -> Editor -> Formatting
Language: PHP
Category: Braces
Select "same line" for all
回答2:
Agree on a shared coding style! Don't rely on your editor to format and unformat code for you.
As for this example, I would argue that using brackets is better since it's less error prone - but this is something you have to agree upon with your collegues!
回答3:
Ok so it isn't possible I guess.
回答4:
It is possible to format braces in PHP.
This is an example:
回答5:
I finally found the answer to this. It is found under Options -> Editor -> Formatting -> select PHP under the language drop down -> select "Wrapping" category -> scroll down to see "If Statement" and select "Never".
来源:https://stackoverflow.com/questions/13801657/netbeans-code-format-braces-in-php-single-line-statements