Netbeans code format braces in PHP single line sta

2019-06-25 23:03发布

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?

5条回答
▲ chillily
2楼-- · 2019-06-25 23:45

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

查看更多
地球回转人心会变
3楼-- · 2019-06-25 23:45

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!

查看更多
甜甜的少女心
4楼-- · 2019-06-25 23:47

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".

Netbeans screenshot

查看更多
▲ chillily
5楼-- · 2019-06-25 23:50

It is possible to format braces in PHP.
This is an example:

enter image description here

查看更多
老娘就宠你
6楼-- · 2019-06-25 23:58

Ok so it isn't possible I guess.

查看更多
登录 后发表回答