Skip to main content

Five tips for PHP newbies

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:

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 or tool may become the main requirement of one of your projects.

5 thoughts on “Five tips for PHP newbies

  1. While analysing code of famous open source products is good advice some open source products like phpbb and oscommerce even though are work well are not coded according to the highest standards.

  2. I agree with you that not all open source applications are epitome of highest coding standards. Still you can pick a lot of tips and hints even from these applications.

    For example, you can learn how to store sessions in database from OsCommerce or how to design the schema of an e-commerce site. And you don’t have to copy the code word by word either. Analyzing others’ code will give you enough food for thought to implement your own solutions.

  3. I installed PHPbb3 the other day on my website, and realized how ridiculous the entire application is. With it’s insane amount of styling and module possibility it creates huge problems if you are just trying to update the forum version. Most modules require changing phpbb’s main source, and that was very unnerving, it was supposed to be an addon not a patch. Don’t make module approached php sites that require patching of the main tree for it to work. I like the files for a single module to stay with that module.

  4. Tip One: Don’t use XAMP :

    I find it so much easier to show people how to setup and work with a LAMP stack on a small computer or a Raspberry Pi, plenty of power for day to day development and learning plus if you get it wrong, start again.

    Alias your local server to a random domain name with your windows hosts file and you are away.

    Great tips

Leave a Reply

Your email address will not be published. Required fields are marked *


*