Most of the time when I need to wrap some code onto the next line I have a preferred way of doing it. For example when calling a method I like to :
someMethod(
param1,
param2,
param3
);
but when it is a method definition I can’t find a way that reads intuitively. EG
function someMethod(
param1,
param2,
param3) {
// code here.
// Problem : The parameters are indented at the same level as the code
}
function someMethod(param1,
param2,
param3) {
// code here
// Looks ugly. Pain to re-factor
}
public function someMethod(param1, param2, param3
param4, param5, param6) {
// code here
// I've included public to show that I am using 8 spaces here and not
// lining up with the end of the function keyword.
}
I’m leaning towards the last example, but am not very happy with it. It works ok with the opening brace on the end as here, but if the brace is in line with the function keyword it looks ugly. eg
function someMethod(param1, param2, param3)
param4, param5, param6)
{
// code here
}
Edit: I’m primarily asking about PHP, but I’ve had this problem in other languages.
I suggest you to follow a coding standard. There are many good and popular ones.
In my particular case, I program in PHP, so Zend and Pear come to my mind. Also, if you aren’t programming on a team, then coding style is mostly something of your particular taste and being consistent.
Anyway, in those standards they recommend something like this: