Top Tips to becoming a better PHP developer.

With at least 20 million domains using it, including some of the busiest such as Wikipedia and Facebook, PHP is probably the world’s most popular web development language.

To help you get to grips with this demanding language, we’ve put together some top tips to becoming a better PHP developer.

Top Tip 1 - Use PHP functions and classes

PHP has core functions and classes to make your life easier. So if you’re looking to do something reasonably common, it’s worth taking a look through the PHP manual before you get started with creating your own functions. For example there are existing functions and classes that get rid of white space at the beginning and end of a string (just use the trim () function).

Top Tip 2 –Create a master file

By creating a master file for your database connection settings and including it in your PHP scripts, if you ever need to change details you only need to change them in one file rather than multiple files. Using a configuration file like this is a great way to make your code easier to manager.

Top Tip 3 – Sanitize your data

Sanitizing your data when inputting it is the only way to stop SQL injections from causing you havoc. This is all part of learning about ways your application can be compromised – and luckily PHP have a core function (see top tip 1) which will sanitize your regular string inputs: mysql_real_escape_string. Using htmlspecialchars is another function which will help protect your database as it converts html characters and safeguards your application against cross-site scripting attacks.

Top Tip 4 – Leave error reports switched ON

When developing an application its likely you will come across some errors. Leaving error reports switched on makes finding and solving the error much easier. Error reports can be set up in your server’s php.ini file or you can set them on top of your own PHP scripts by using the ini_set () function and setting display_errors to 1. Setting error reports on top of your own PHP scripts however does have its limitations so if you can access the server php.ini files it’s probably best to set error reports from there.

Top Tip 5 – Over commenting is bad!

Comments are great but it’s not necessary to add comments to every line of code. Too many comments over complicate things and good code should be pretty self-explanatory most of the time!

Top Tip 6 – Keep and re-use your old code

As you go through your career as a PHP developer, you are likely to come across the same challenges time and time again. As a result it’s a good idea to keep hold of and re-use any particularly good pieces of code or pieces you think you might use again. Most integrated development environments have built-in features for exactly this purpose.

Top Tip 7 – Make the most of available help with editing.

Editing is one of the biggest time consuming processes in developing code for your application, as a result to save you time; you need to get a good editing tool. Sytanx highlighting should almost certainly be included and other optional benefits you should look for are code hinting, code navigation and built-in de-bugging tools. In order to get the most from these tools it’s important to learn about your code editor’s features before you get going.

Top Tip 8 – Use a PHP Framework

Using a framework may seem like hard work in the first instance as you’ll need to get to grips with how the framework itself works, but in the long run using a PHP framework will pay off, especially when you have to share your code or work alongside someone else. Using frameworks such as CakePHP, CodeIgniter, Symfony and Zend offers you a standardized platform for building your web applications.

Top Tip 9 – Find a MySQL Admin tool and use it

When you’re getting started in PHP it’s important to get to know how to work with MySQL via command line, however when you’re developing a lot of code it’s incredibly time consuming to manage your database in this way. Using your MySQL admin tool you should be able to build databases and their tables quickly, export your databases in to SQL files, optimize you tables, check for any issues there might be, run SQL queries and create MySQL database users in a much more time efficient manner.

Top Tip 10 – Network

PHP is a massive subject to learn and your probably never going to know it all, so network, get involved in PHP forums and chat with other PHP developers. Sharing your experiences and sometimes even your code snippets can be hugely beneficial and keeps you learning and developing throughout your career.

Using these top tips should help save you time and keep learning how to develop great code.

Find PHP job by clicking here