Lay the foundation
The Develop rock-solid code in PHP series is about solving practical real-life problems in medium- to large-scale applications. With a sharp focus on new features available in PHP 4, the articles shed light on numerous tips and tricks that make life easier. Inside, you will find plenty of examples and techniques to learn, with lots of sample code. In this first article, PHP veteran Amol Hatwar gives a higher perspective for designing and writing bug-free, maintainable code for medium- to large-scale Web applications.
If you are a developer building Web applications and need speed, functionality, and platform-independence, then PHP is for you. Moreover it is free, easy to learn and deploy. These are the greatest strengths that makes PHP so popular. But these same strengths can also become weaknesses. Because of PHP's ease-of-use, developers often start by hammering code into their editors when they should have really been planning and designing. Also, you can solve a problem in more than one way in PHP and the dangers of making painful mistakes that become difficult to fix later are never far away.
In this series of articles, you will learn how to avoid many mistakes. If you follow through faithfully, do not be surprised to find yourself writing bug-free code at the first or second attempt. I will also point out new features available in PHP 4 that make life easier. Most of the examples that I will cover deal with practical, real-life problems like script configuration and setup, file handling, and database usage. Even if you are new to all this, you should find it easy to follow. However, I will assume that you know elementary PHP. If you need to brush up, you will find the resources outlined at the end of this article helpful. (See Resources.)
Lay a rock-solid foundation
Coding in PHP is very much like coding in a language like C. They are syntactically similar which can also lead to similar code maintenance problems. When large-scale applications have to be developed, large quantities of code may be written. Over time, this code may become unmanageable and soon bugs creep in. Wherever you heard this, it is untrue -- at least partly. But the bigger truth is that if you find yourself maintaining your code too often, your application was probably poorly designed in the first place.