Monday, June 29, 2009

Five ways to be a better PHP programmer

Here is a list of five things you should do (or not do) when you are starting out with PHP.

Don’t use XAMPP or PHP Triad

This is one of the most common and absolutely the worst mistake PHP beginners can make. Go to any PHP forum and you will see scores of threads on people looking for help on how to change their PHP settings.

If you want to earn a living through PHP coding, you should at least know how to install Apache and PHP. You don’t need go too deep into Apache configurations. Just enough to get the Apache-PHP combo up and running so that you are familiar with the php.ini file.

This knowledge will be immensely helpful when you start deploying web applications on production servers.

Set error reporting level to maximum

Configure your development environment to display all PHP warnings, notices and errors. This will help you code better and also help in catching potential bugs early in development phase.

You can change the error reporting level at runtime by adding the following code at the top of your PHP script:


// Report all PHP errors.
error_reporting(E_ALL);
?>

You can also control whether you want to display errors in the browser itself or whether you want to log the errors. Note: Displaying errors is not recommended for production servers.

Always check the manual first

Stuck on PHP coding problem? No sweat. Just checkout the PHP’s online manual, especially the User Contributed Notes. Chances are somebody has already faced your problem and has also figured out the solution. User contributed notes are full of useful hints and tips.

PHP is perhaps the only language whose manual is much more comprehensive than most of the books available in stores.

Analyze code of open source applications

Download some popular open source PHP applications and study their code. Analyze how they have implemented things. Figure out their database schema.

This is very useful for PHP beginners who have no problem grasping the syntax but struggle on implementing and developing websites and web applications.

Be flexible in your approach

Do not give into preconceived notions. Be flexible in adopting technologies and programming techniques. Don’t form too strong opinions against OOP, templates and frameworks. One never knows when a particular technology may become the main requirement of one of your projects.


Source:phpsense.com