Some General Tips

Documentation 
————————————————– 
* traditional PHP comments embedded in code that might be a little confusing (if borderline – comment!) 
* using phpDocumentor to at least thoroughly comment widely used base classes/code. use @package, @subpackage to group thing. see phpdocumentor website for more details: http://phpdoc.org/ 

Autoload 
————————————————– 
Using the new autoload functionality (http://us2.php.net/autoload), include pains are a thing of the past. Also ensures that files/classes are only included if and when needed. Remember to intelligently name classes & files. See me or the link for further information. 

OOP 
————————————————– 
Using objects and OOP design has many benefits including organization, reusability, multiplicity, and they’re easier to debug. 

Remember: Using classes != OOP 
————————————————– 
Quoted from http://www.onlamp.com/pub/a/php/2005/07/28/oo_php.html 

I myself experienced the pitfall in the beginning of my PHP enlightenment, but the light shone again and my eyes opened to the use of OO PHP. What I mean by OO PHP specifically is the use of classes, not just simple function blocks. Many new developers feel that classes are useless, cumbersome, and time-consuming. Given the unique nature of how PHP actually works, it is possible to throw functions in the code at any point on the page and start using them immediately. If this is the case, it is possible to include a page of functions at the top of the page and go to town with them. Now, while it is possible to do this–and using classes isn’t very far from it in some aspects–there are numerous benefits and advantages to actually using classes instead of simply using a list of functions. 

Testing & Code Testability 
————————————————– 
Design and code things so that they can be tested independently. Then run tests on those individual segments of code. Ideally also create a test page which runs through as many tests as possible, giving ‘pass’ or ‘fail’ notices for each test. Run the tests after new development to find bugs. 

Security 
————————————————– 
Validate as much as possible. Especially when accepting input from the browser/user. Never modify the database the database without escaping values. Never rely on register_globals (because of security and because it is now deprecated). 

Coding Standards 
————————————————– 
Following coding standards will make code easier to read and easier for code to be worked on by multiple people. See http://pear.php.net/manual/en/standards.php 

Don’t Re-Invent the Wheel – Use Pear! 
————————————————– 
Pear has a lot of very useful packages. It’s a good idea to get familiar with their offering and use the packages whenever possible. It saves dev. time. http://pear.php.net/ 

Note: MDB2 is their current database package. It’s quite useful and easy to learn. See http://www.phpied.com/db-2-mdb2/ for a quick tutorial.

Leave a Comment