Senior Trainer-Instructor- Developer C++ / C UNIX & Web-JAVA / J2EE,PhD or Masters
WSI Nationwide, Inc.
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Best Practices: PHP Coding Style
One of PHP's greatest strengths can also be a great weakness in the wrong hands. I'm talking about its forgiving nature. One of the reasons why PHP has become so wildly popular is because it lets very inexperienced web developers build powerful applications without much planning, consistency, or documentation.
Unfortunately, that means an awful lot of PHP code out there is sloppy, hard to read and impossible to maintain. I know because I've written a lot of it ;-).
To address this and a lot of other issues, a number of the core PHP developers and community members got together and started the PEAR Project, which stands for PHP Extension and Add-on Repository. To date, the docs and other fruit from the PEAR project have been pretty sparse and difficult to follow, so this article is an attempt to shed some light on what they're doing.
A pretty huge part of maintainability of code is how it is formatted and commented. All code throughout a given project should be formatted the same way. I'm a pretty big stickler about this in the SourceForge codebase and you should be too.
[ Next Page ]


Comments:
Content management question Rocky 05/31/07 03:23
In need for codeMichael02/10/05 08:18
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø12/07/04 02:40
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø12/05/04 06:06
Ä«,µå,¿¬,ü,ÀÚ/¿¹.Á¤.ÀÚ ´ë,Ãâ 100-1000¸¸¿øÀÌ´ÙÇö12/05/04 01:43
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¿í12/04/04 10:57
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø11/24/04 06:06
½Å.¿ë.ºÒ.·®/Ä«.µå.¿¬.ü/´ë.Ãâ/È¥ÀÚ/ÇØ.°áÇÏ´Â/¹æ.¹ý±èÇö¼­11/24/04 00:34
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¹Î11/23/04 06:29
½Å.¿ëºÒ.·®ÀÚ°¡ ¾Ë¾Æ¾ßÇÒ Á¤.º¸ ´ë.°ø.°³ ÀÌ´ÙÁø11/21/04 21:30
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÁ¤¿¬11/18/04 09:48
Ä«.µå °ª.¿ø.±Ý.¸¸.°±.´Â.¹æ.¹ý(°­.Ãß)Áö¿µÈñ11/14/04 19:44
Coding Standards and ConsistancyBruce Painter09/12/04 01:48
Use tabs?!? What the ??thujone04/29/04 11:38
Ä«µå¿¬Ã¼/½Å¿ëºÒ·®ÀÚ¿¡°Ô ²À ÇÊ¿äÇÑ Á¤º¸!!!¼­ÇöÈñ01/06/04 23:33
½Å¿ëºÒ·®/Ä«µå¿¬Ã¼/È¥ÀÚÇØ°áÇÏ´Â ¹æ¹ý!!(Çʵ¶) µµ¿ì¹Ì09/29/03 22:38
my preference on indenting/curliesgLaNDix08/07/03 13:02
Bracing styleAvi Marcus07/18/03 01:01
stringsTom04/16/03 06:13
RE: Tabs Cause ProblemsLeon03/26/03 06:49
RE: Braces should be on their own line, probaEric Kok01/09/03 08:35
RE: Braces should be on their own line, proba/zureash01/02/03 11:45
RE: Using braces properly -- DON'T!!Eugene Wee10/28/02 21:18
RE: Braces should be on their own line, probably.Drew10/22/02 15:27
SuggestionDaniel09/17/02 04:24
RE: ALLopinion08/12/02 13:22
RE: nice stylesveno07/21/02 06:54
RE: PHP for beginnersNick07/20/02 11:55
RE: people, get it thru your headJames Young07/11/02 12:12
RE: setting indent spaces in vimSteve Sutton07/11/02 09:37
RE: PHP for beginnerssam07/04/02 04:49
RE: people, get it thru your headAdam Ellis07/02/02 14:22
nice stylePete07/02/02 14:18
setting indent spaces in vimDave07/01/02 16:07
strings and quotes - some test resultsmaren06/26/02 09:06
newbieeeVikram05/22/02 04:43
Coding style examples are "CORRUPT"Razzbar05/15/02 20:42
Micro$oft bug free?coditza05/14/02 19:42
abt codding stylelarry05/10/02 10:11
This looks betterMatt04/25/02 14:50
RE: people, get it thru your headRazzbar04/21/02 17:54
Yet Another OpinionMark04/11/02 16:06
Dirty code - not only PHPJames Linden04/07/02 21:10
send forumlialy04/05/02 16:31
RE: How about aligning those curly braces?olabri03/25/02 08:36
RE: Learning PHPAlex Davies03/24/02 07:37
Referencing a single image-pathBrian03/19/02 21:18
RE: Special characters in text filesJan02/21/02 21:06
proper uses of include and include_onceChris Travers02/18/02 21:05
Now we see the real from the wanna-beJackansi02/06/02 10:07
RE: PHP Hurts my head...Kevin01/31/02 22:47
RE: people, get it thru your headKevin01/31/02 22:45
RE: <? PHP Sucks ?>Kevin01/31/02 22:43
RE: My StylePeter Daemen01/28/02 09:42
RE: Style/brackets ect......Peter Daemen01/28/02 09:39
RE: people, get it thru your headthomas whalen01/27/02 03:51
<?php [php???] ?>Qwik01/24/02 18:27
PHP Hurts my head...Steven01/21/02 19:49
RE: people, get it thru your headNicole01/16/02 11:22
RE: <? PHP Sucks ?>Nicole01/16/02 11:06
Special characters in text filesOwen Lysaght01/15/02 19:13
RE: <? PHP Sucks ?>Rod K01/14/02 22:58
RE: <? PHP Sucks ?>kr0m301/14/02 10:47
RE: <? PHP Sucks ?>Cory01/12/02 17:35
RE: <? PHP Sucks ?>Jean01/04/02 00:26
RE: <? PHP Sucks ?>Daniel Perry12/30/01 15:14
Other probs with ASP tags etc - compatibilityDaniel Perry12/30/01 14:41
Style/brackets ect......Peter12/17/01 00:59
RE: <? PHP Sucks ?>Peter12/17/01 00:50
Using braces properly -- DON'T!!Mike12/10/01 07:42
RE: My Style...Pacmon11/27/01 10:08
RE: people, get it thru your headNealC11/22/01 11:42
RE: How about aligning those curly braces?RChaneau11/21/01 12:09
Creating and Commenting If StatementsMihkel Karu11/04/01 14:23
My StyleDKMan10/11/01 10:01
RE: Becoming a Great WebmasterKnight10/08/01 22:28
RE: Becoming a Great WebmasterLuciano ES10/08/01 10:43
How about aligning those curly braces?Luciano ES10/08/01 10:11
My StyleJonatas09/24/01 10:14
RE: <? PHP Sucks ?>Shane A09/19/01 19:20
RE: <? PHP Sucks ?>Patrick Altman09/10/01 20:37
RE: <? PHP Sucks ?>Micheal08/31/01 09:04
My Style...c0d34w4y08/25/01 17:02
My StyleDustin08/22/01 20:53
RE: Interesting...jimbarry08/22/01 13:04
php editormemoir08/14/01 20:09
RE: <? PHP Sucks ?>MikeQ08/11/01 12:14
RE: php reformatters?Carl Heaton07/26/01 07:34
More on If StatementsAdam Sharp07/23/01 18:10
RE: My style.. Abraham Godong07/19/01 00:31
Where?????Fadi Aboualfa07/16/01 11:04
beginning with phpsgelinas06/20/01 13:27
RE: <? PHP Sucks ?>Mike Hall06/18/01 02:27
RE: php & htmlyl82806/10/01 01:37
RE: <? PHP Sucks ?>Dolce06/08/01 01:18
Looks good but....Jeff06/07/01 09:12
RE: PHP for beginnersAnne06/04/01 04:10
RE: Including Code (no once)Eric Blade05/30/01 00:15
php & htmlpeppe05/17/01 06:31
RE: Including Code (no once)Miguel Cruz04/21/01 23:42
RE: PHP for beginnersEric Blade04/13/01 23:36
RE: ASP tags OKEric Blade04/13/01 23:35
RE: PHP for beginnersErika Pimmer-Schniedermeier04/09/01 15:03
One more commentDean Hall04/07/01 23:20
General comments on PEARDean Hall04/07/01 23:18
ASP tags OKDean Hall04/07/01 23:11
single quotes vs double quotes and stringsEric Blade03/26/01 12:46
RE: Checkboxesboese03/24/01 04:33
Where can I find some short Php docs ?Chris03/23/01 11:38
Including Code (no once)Eldes :: MZO Interativa03/23/01 09:56
braces and indentationcrankydoodle03/21/01 01:59
RE: Checkboxes Patricio Anguita03/19/01 17:30
RE: TabsMarc03/16/01 13:20
RE: HTML and PHPDave Kingdon03/10/01 10:23
Shopping card prog with PHPGökmen CIFTCI03/10/01 08:31
RE: Becoming a Great WebmasterPlutarck03/10/01 00:31
RE: ASP tags are discouraged?? HOLD IT!SonOfDad03/09/01 10:26
RE: PHP for beginnersSonOfDad03/09/01 10:20
PHP for beginnersPHPwannabe03/08/01 14:43
RE: Differences in quotesphilip olson03/05/01 21:46
RE: ASP tags are discouraged?? HOLD IT!Stephen Sandison03/02/01 00:55
OTB again?!Tad Marko03/01/01 08:37
RE: Old Challenges Renewed (Hey, Kyle?)Bogs02/28/01 09:54
Checkboxesshiv shankar02/27/01 03:39
Problem send greeting cardalia02/08/01 23:11
in sum?OOZC02/08/01 14:17
speed?Nass02/06/01 03:03
Differences in quotesKeegan Miller02/04/01 23:12
RE: SQL StatementsKeegan Miller02/04/01 23:01
My style.. ellis of geeknews.com01/30/01 04:52
Coding StyleAndrew Tejero01/29/01 23:13
How to do this?ColdFusion01/27/01 15:47
RE: Braces should be on their own line, probably.Carlos Viana01/27/01 06:13
RE: HTML and PHPCarlos Viana01/27/01 06:01
RE: ASP tags are discouraged?? HOLD IT!Giovanni Moretti01/26/01 03:30
people, get it thru your headRon McKown01/20/01 01:07
ANSI CMundi King01/19/01 15:15
RE: ASP tags are discouraged??Peter Be01/18/01 04:48
RE: ASP tags are discouraged?? HOLD IT!golem01/17/01 19:34
RE: HTML and PHPgood voice01/16/01 06:02
RE: Code Style - The Right Way:)good voice01/16/01 05:49
RE: Code Style - The Right Way:)Henry01/15/01 18:33
Double quotesDevendra01/15/01 07:07
RE: <? PHP Sucks ?>Gilbert Rehling01/14/01 11:39
RE: Becoming a Great Webmasterpaul01/13/01 16:43
<? PHP Sucks ?>John01/12/01 13:50
Becoming a Great WebmasterC. Carter01/11/01 11:35
Code Style - The Right Way:)Paul K Egell-Johnsen01/11/01 07:38
HTML and PHPSimen Brekken01/11/01 04:32
StringBiTDaemon01/10/01 21:40
RE: Paul's, Brian's, and Morpheus' postsAnthony Boyd01/10/01 01:10
if...then statementsmike01/09/01 22:35
RE: A pariah perhapsBjörn Brändewall01/09/01 17:33
RE: line wrappingBjörn Brändewall01/09/01 17:12
VIM Setup for Good FormRex Byrns01/08/01 14:27
TEMPLATES TEMPLATES TEMPLATES! Benjamin Smith01/07/01 00:41
Also about tags...Henry01/06/01 19:46
RE: Commenting BracketsAnna01/06/01 00:49
[PHP-PEAR] RFC: coding standards documentphilip olson01/05/01 23:02
Control structuresShanx01/05/01 10:26
RE: Paul's, Brian's, and Morpheus' postsmorpheus()01/05/01 06:33
RE: Old Challenges Renewed (Hey Kyle)morpheus()01/05/01 06:27
RE: 2 quibbles: Indenting and bracketsKelli01/05/01 01:05
RE: Function/Variable namingWes Maldonado01/04/01 17:51
ASP tags are discouraged?? HOLD IT!Brett Tesdall01/04/01 17:48
open and close curliesScott Marlowe01/04/01 12:43
RE: Braces should be on their own line, probably.Kevin Clark01/04/01 10:10
RE: A pariah perhaps (Ericson Smith)morpheus01/04/01 03:51
Function/Variable namingPeter Feiner01/03/01 20:25
RE: Braces should be on their own line, probably.Ara01/03/01 13:43
Braces should be on their own line, probably.Thomas Hurst01/03/01 09:15
RE: Old Challenges RenewedThomas Hurst01/03/01 09:07
RE: php reformatters?Cecil A. Galbraith01/03/01 07:56
What about effecient coding??!!?Trond01/03/01 07:41
RE: Tabs vs. SpacesRoel01/03/01 06:08
RE: SQL StatementsJan Lehnardt01/03/01 05:59
RE: SQL Statementskjj01/03/01 02:24
RE: Religion and ProgrammingChris Lee01/02/01 20:58
RE: Browsers and spacesVincent Vollers01/02/01 20:41
HIT MEnat01/02/01 18:24
RE: php reformatters?ff3j01/02/01 17:55
Browsers and spacesErik J. Barzeski01/02/01 17:54
Religion and ProgrammingTom Anderson01/02/01 17:00
Tabs ;-)Tim Perdue, PHPBuilder.com01/02/01 16:12
GNU StyleCharlie Collins01/02/01 16:08
RE: Tabs vs. SpacesCharlie Collins01/02/01 16:04
RE: Paul's, Brian's, and Morpheus' postsAnthony Boyd01/02/01 15:33
php reformatters?hollins01/02/01 14:54
RE: Tabs vs. SpacesBryan Brunton01/02/01 14:48
INDENTING... What I prefer to read :André01/02/01 14:34
it's about consistencyStephen VanDyke01/02/01 14:05
That's really not the 1/4 of it!Ken Egervari01/02/01 13:29
RE: A pariah perhapsTom Anderson01/02/01 13:28
tip about commentsRicardo Leite01/02/01 13:13
Old Challenges RenewedKyle01/02/01 12:50
Old Challenges RenewedKyle01/02/01 12:50
RE: A pariah perhapsEricson Smith01/02/01 12:42
Devils advocateRichard Wallace01/02/01 11:39
IncludesErik J. Barzeski01/02/01 11:13
RE: line wrappingluke chasteen01/02/01 11:06
RE: Naming conventionsluke chasteen01/02/01 10:51
RE: A pariah perhapsluke chasteen01/02/01 10:49
RE: It is easy to get a good coding styleJason Lee01/02/01 10:25
Great TimFabrizio01/02/01 10:25
A proposed "grammar" for commentsGanesh Prasad01/02/01 10:10
RE: line wrappingChris Newman01/02/01 09:42
RE: indentTim Wasson01/02/01 08:57
BracesPablo01/02/01 08:04
OO / Database / SQL AdditionVincent Vollers01/02/01 07:28
RE: A pariah perhapsVincent Vollers01/02/01 07:27
SQL StatementsAnderson Fortaleza01/02/01 07:16
RE: Commenting BracketsWayneH01/02/01 07:08
RE: It is easy to get a good coding styleGlen Scott01/02/01 06:44
A pariah perhapsmorpheus()01/02/01 05:51
Naming conventionsJonathan Kahn01/02/01 05:45
It is easy to get a good coding styleLars Dybdahl01/02/01 04:24
FantasticRick01/02/01 02:59
Commenting BracketsBruce01/01/01 22:58
Tabs vs. SpacesBrian Mertens01/01/01 21:56
indentpaul01/01/01 21:49
RE: Interesting...Sam01/01/01 20:11
line wrappingJustin01/01/01 18:14
Excellent!Sean Grimes01/01/01 16:06
RE: Interesting...Jan Lehnardt01/01/01 11:02
Indenting...Mike01/01/01 01:05
2 quibbles: Indenting and bracketsPaul Meagher12/31/00 23:10
Very niceArni12/31/00 21:20
Thanks .. :)Ryan12/31/00 18:15
Interesting...Chris S12/31/00 17:10
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.