PHP formatting practices
Posted: Sat Mar 26, 2011 5:40 am
Hello again all 
I have a hopefully very quick query about generally accepted practices when writing PHP. PHP ignores most whitespace, giving you a lot of functionally identical options when writing your code. I was wondering whether there were some clear, widely accepted practices around this, or whether it's a matter of personal preference?
I've always been in the habit of writing PHP with a minimum of whitespace. I put a line break in (1) after a semicolon; (2) after a left curly bracket; (3) before and after a right curly bracket. So like this:
Other developers put in a lot more whitespace, like this:
Is there a "right" way to do things here? It seems pretty much personal preference as to which is actually easier to read (I find all those extra line breaks make it very hard to read, but evidently other people don't!) but I wondered whether I should be changing to match the way other people do it.
I have a hopefully very quick query about generally accepted practices when writing PHP. PHP ignores most whitespace, giving you a lot of functionally identical options when writing your code. I was wondering whether there were some clear, widely accepted practices around this, or whether it's a matter of personal preference?
I've always been in the habit of writing PHP with a minimum of whitespace. I put a line break in (1) after a semicolon; (2) after a left curly bracket; (3) before and after a right curly bracket. So like this:
Code: Select all
function x(){
callfunction($arg1,$arg2);
callanotherfunction($longargment1,$longargment2,$longargment3,$longargment4);
}Code: Select all
function x ()
{
callfunction ( $arg1, $arg2 );
callanotherfunction (
$longargment1,
$longargment2,
$longargment3,
$longargment4
);
}