0

10 PHP development tips part 1

10 PHP development tips part 1

PHP Logo

PHP Logo

Hypertext Pre Processor (PHP) is one of the most widely used web development programming languages in the world. Some of the worlds biggest and most popular websites and open source projects such as Facebook and Drupal use PHP to power their applications. Its popularity is a blight as well as a blessing however as building a reliable and secure environment in which to develop and serve your applications is extremely difficult for the uninitiated. PHP is easy to use which makes it easy to write bad code. Developing applications in PHP is rife with stumbling blocks and the possibility of mistakes arising. It is very important when developing anything to keep certain considerations in mind.

This post intends to communicate 10 such considerations with which to improve your PHP applications and avoid common mistakes.

1. Use a good IDE

Used alone PHP is a very powerful programming language. Used with a suitable Integrated Development Environment (IDE), PHP becomes even more powerful. IDEs provide extra features built around the basic PHP functionality. Things like an integrated debugger, live preview, error messages, tooltips, code templates code generation, refactoring, project and file management, source code revision control and support for popular PHP frameworks plus many many others.

I use the Netbeans IDE for my PHP development, it is cross platform compliant and handles the technologies I use such as: GIT, MySQL and HTML5.

There are many other IDEs such as Eclipse and Aptana Studio but I find these are resource hogs. You can find a list of PHP IDEs here.

If you don’t want to use an IDE a good language independant source code editor is Notepad++ which is free and has many useful plugins that provide some of the core functionality of an IDE without the overhead of using one. A list of editors are available here.

2. Use a framework if you need one

It’s a useful skill to be able to develop a website from scratch, but when it comes to security and reliability it’s more than likely been done before and done better to boot. Therefore it is usually beneficial for you and inevitably your users to use a pre existing framework when implementing your sites intended functionality.

There are many frameworks available and they vary in the features they provide. One framework that I’m especially fond of CodeIgniter. PHP frameworks provide a set of libraries for commonly required functionality such as Database Access, File Access, Email functionality and integration with other tools, features and frameworks.

There are many advantages to using a framework such as speed of development, security and reliability.

Frameworks are usually open source which means you can benefit from having an entire community around you which feed improvements and bug fixes back into the project.

3. Read the manual

Should you have a question or issue with PHP or one of it’s associated technologies, your first port of call should be the PHP Manual. The manual is an incredible resource for any PHP programmer wanting to know pretty much anything there is know about any PHP feature or function. Where the manual really shines is in it’s user contributed comments beneath each manual entry, I’ve lost count of the number of times the comments have put the technique into context and even provided a solution for the problem I was experiencing.

4. Follow a recognised coding standard

There are two ways of writing code, the right way and the wrong way. The right way will save you time whereas the wrong way will waste your time and frustrate you, your colleagues  your manager and any future maintainer of the code base you create.

A good way to write code is to follow an industry recognised coding standard. There are several of these and some are highly language dependant. When it comes to PHP however one of the most adopted ones are the PEAR Coding Standards.

Coding standards aim to keep code consistent to be easily readable and maintainable by most develops using that language. They lead to less confusion and can aid in the detection of bugs.

5. Refactor as you go along

Refactoring is the process of changing the internal structure of a piece of code whilst maintaining it’s behaviour from an external perspective. Refactoring improves your software. It makes it more robust, efficient, reliable and easier to understand. The reason we refactor is to improve code, maybe you found a better way to implement an algorithm? The beauty of refactoring if done properly is that it allows you to change the inner structure of a piece of software whilst maintaining its functionality and appearance to end users in terms of any API that might be available. for more information regarding refactoring see this Wikipedia article.

Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.

The second part of this article will follow soon, subscribe to my feed either by E-mail or by RSS to receive updates as they happen.

Jason Edwards