Zend Developer Zone | The Best Tool For The Job: OO versus Procedural Programming in PHP
May 15th, 2007 by Giles SmithIntroduction
“True genius resides in the capacity for evaluation of uncertain, hazardous, and conflicting information.” (Winston Churchill)In PHP, unlike many other languages, you can choose between using an object oriented (OO) or a procedural approach. Most PHP programmers use a procedural approach by default, since web pages themselves operate in a very procedural way (this tag, then this tag, then this tag). Interspersing procedural code with HTML is more straightforward, and so PHP programmers often develop their own style, based on this approach.
If you are new to PHP, procedural programming is probably the only kind of programming you are familiar with. However, if you have been exploring the PHP community for best practices, by now you have probably seen posts in forums and newsgroups about “object bloat”. You have probably also seen tutorials on how to write object oriented code in PHP. You may have downloaded libraries that employ classes, and learned to instantiate their objects and use their methods. Yet it is quite possible that you have never really understood when, where, or why it is appropriate to use an object oriented approach.
There is a certain amount of ranting on both sides of the issue, and slogans such as “Objects are bad!” or “Objects are good!” are sometimes heard. This article does not attempt to decide between the two approaches and come up with a single “best practice”, but to explore the advantages and disadvantages of each.
Want More? Here is something related:
- 08 Aug 2008 -- Good Bye PHP 4
- 17 Mar 2008 -- PHP second only to Java, according to Google Trends
- 03 Nov 2007 -- Ajax File Uploading