02 Sep 2008
Class and function declarations have their opening brace on the same line, and follow a modified "K&R style".
Class Definitions
class Foo { //... code goes here }
Function Definitions
function fooFunction($arg1, $arg2 = 'default') { if (condition) { statement; } return $val; }
Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Here is a slightly longer example:
function connect(&$dsn, $persistent = false) { if (is_array($dsn)) { $dsninfo = &$dsn; } else { $dsninfo = DB::parseDSN($dsn); } if (!$dsninfo || !$dsninfo['phptype']) { return $this->raiseError(); } return true; }
Modified K&R Braces
I'm a recent convert to braces on the same line, but if my recollections and observations are correct, a lot of the existing Zoop code isn't this way, instead following the "braces line up vertically" standard.
Are we planning to convert everything, or just tolerating both for a while?
Same Line
I am a big fan of the same line curly brace because it removes a lot of unnecessary whitespace.
Transition is ok
If someone wants to write a nice regex to convert it, by all means do it. Other than that, I am fine with only future code mandatorily conforming to the standards and slowly changing the old code to match.
----------------------------------
Co-Author of Zoop Framework
http://spf13.com