Tips to Become a Good PHP Developer

PHP is one of the most popular web development language. PHP has gained quite a following in recent times, and it is one of the front runners in the Open Source software movement. Its popularity derives from its simplicity. One of the best things about PHP is that it’s a great language to just “start with”.


Below mentioned guidelines will be helpful for you if your taking you first step into this awesome web development language.

1. Make use of PHP Core Inbuilt Functions and Classes

If you are implementing a common functionality then there are changes that there will be a PHP function or class that you can use and take advantage of it.

It’s always good to first check the PHP manual before writing your own functions. Those functions actually works as a time saver for you. We can fulfill our basic functionalities by using PHP functions. PHP has a huge library of functions. A simple example of this is why to create a function which will convert a string to array when you can just use the explode() function which returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter.

2. Use a Configuration File

Instead of having the database string in every file, you can create one main file that contains the database settings and then include it in your PHP scripts. If required you can change details later on. It is always better to make the changes in one file instead of several files. This is also very useful when you need to use other constants and functions throughout multiple scripts. Using a config file is a popular web application pattern that makes your code more modular and easier to maintain.

3. Always Sanitize the data that goes in database

SQL injections is more common and big problem. Sanitizing the data that goes in your database is the simplest way to get rid of the problem. The first thing you should do is to get a good understanding of what SQL injections are and what are the ways in which you can protect your application from it. Check if you can get more examples of SQL injection attacks.

mysql_real_escape_string is one of the great PHP function that can help to overcome this problem.

mysql_real_escape_string takes a regular string and sanitize it for you. Using mysql_real_escape_string with htmlspecialchars, will not only protect your database, but it will also safeguard your application against cross-site scripting (XSS) attacks when rendering user-submitted HTML such as posted comments or forum threads.

4. Keep Error Reporting Turned On in Development Stage

When building your application always keep the error_reporting and display_errors turned on to see run-time errors. This method will help you quickly identify where errors are coming from.

These run-time configurations can be configured in your server’s php.ini file. If you don’t have access to make these configurations, then you can set them on top of your PHP scripts using the ini_set() function to set display_errors to 1. But this method has its own limitations when it is done in this way.

The only reason to keep these error reporting ON is quite simple, the earlier you know about your errors, the faster you can fix them. You might ignore the warning messages that PHP give you, but even those usually indicate towards a memory-related issue that you can take care of. After your application is ready, turn error_reporting and display_errors off.

5. Add proper comments to code, don’t over-comment

Proper code commenting in your scripts is definitely a good practice, but that does not mean that you should comment on every single line. Normally you should comment the complicated parts of your code so that when you revisit it later you’ll quickly remember what’s the code about. A Good code is self-explanatory most of the time.

6. Favorite Code Snippets should be quickly accessible

In your development career you code same things many times, you should always keeping the code snippets available with you which will help you save a lot of time.

Now a days there is lot of apps that will keep and sync your code snippet collection for you.  No matter where you are you will always have your snippets available with you. Some of the apps that you can use for your code snippets are Snippet, Code Collector and Snipplr.

Most integrated development environments (IDEs) such as Eclipse and Dreamweaver might have some built-in features for storing code snippets.

Even a simple and organized directory called snippets box that contain text files or PHP scripts and which are synced in the cloud using an app like Dropbox can work for you.

7. Prefer to use a Good Source Editor to speed up your work

You spend your majority of your time on editor, so the editor should be something that helps you speed your work. Syntax highlighting is a must and important. It is definitely something you should be looking for as a software feature. Other feature are code navigation, code hinting and built-in debugging tools. These feature saves your major time.

Take out some time to be familiar with your editor’s features by reading the documentation and reading tutorials online. Investing time in this activity can really streamline your coding workflow.

8. Use Tool like phpMyAdmin for MySQL Administration

You should use a graphical user interface like phpMyAdmin to speed up database development and administration.
phpMyAdmin is an excellent open source database viewer/manager that allows you to view your MySQL databases graphically so that you don’t have to waste time doing things via the command line.

You can quickly build databases and their tables, export your databases into SQL files, run SQL queries, optimize tables, check for issues, create MySQL database users and set up their privileges quickly. If your web host don’t have phpMyAdmin installed, it you can install it few minutes.

9. Use a PHP Framework

Using a web application development/rapid application development framework help a lot. We have a small learning curve in the beginning but you get amazing productivity and efficiency benefits later. Using a framework motivates you to use better web development patterns that you might not be using.

Using a PHP framework becomes useful when you have to share your code with others later on or when you have to work other as a team. It gives you a standardized platform for building web applications.

10. Always be connected with other PHP Developers

You don’t know all the things and even if you think you do, there are thousands of others out there that know how to do something better than you do. So join a PHP community like PHP Developer and interact with others developers. By connecting with other developers you’ll learn better ways of doing the things you’re currently doing.