NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP Coding Standards

Dan Cech dcech at phpwerx.net
Wed Dec 7 10:43:17 EST 2005


cliff wrote:
> If anyone isn't familiar with this, it's worth a read:
> 
> http://www.dagbladet.no/development/phpcodingstandard/
> 
> Nice PHP Coding Standard Guide. I love the part about no magic #s. I would 
> make it required reading for any new team member.
> 
> My only issue is preceding a Class property name with m as in 
> $mClassProperty. m makes me think of method. I'd prefer p for property. 
> Thoughts?

I would be very hesitant to recommend this standard.  I do have a 
particular hate for StudlyCaps so it turned me off right there, however 
the fact is that it hasn't been revised since 2003 and is quite out of date.

There are several references to the old-style $HTTP_*_VARS arrays, and 
no mention of using the superglobal arrays, magic quotes, no discussion 
of single vs double quotes, etc.

That said, many of the more general observations about things such as 
commenting code and using a source management system are very useful, I 
don't know what I would do without SVN (or CVS) for any decent sized 
project.

A more esoteric complaint would be that I prefer tabs over spaces, 
because it allows the developer to control the way code is indented (2 
vs 4 vs 8 etc spaces), and avoids the all-too-common situation of the 
indenting being off by 1 space.  That said, tabs should only be used 
before any text on a line, trailing comments or spacing of assignment 
blocks should be indented with spaces to maintain the layout independent 
of tab spacing settings.

WRT <?php ?> tags, I have embraced a practice I first heard of on this 
list, which is to leave out the end ?> tag and instead use a standard 
comments line like:

// end of script

followed by a single newline (unix-style \n of course)

This avoids the situation where the trailing whitespace after the ?> in 
one of your included files sends output to the browser and breaks all 
your header() and cookie() calls.

The final comment I would give is that the authors refer to 
double-quotes as 'magic quotes' throughout the document.  Considering 
the special meaning of this phrase in PHP this is a very poor choice of 
wording.

Dan



More information about the talk mailing list