. Updated Daily. Editions SDA India   SDA Indonesia
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Friday, 30 March 2007

Article: Why you want Object Oriented Programming in PHP

 

 

Quaint Tech has a new post by Paul van Iterson that explains the issue around Object Oriented Programming (OOP). Traditionally (from the beginning of the computer era), programming was done by combining conditional statements with GOTO blocks to create a program flow. In the early '70s a Dutch computer scientist Edsger Dijksma strongly advocated the use of procedural programming, which means abandoning GOTO statements and creating a sort of chronological program flow in your code (from top to bottom). This style has been widely adapted and for most people is the way they program PHP applications. It is however already a thing of the past. Most modern programming languages are based on an OO approach and don't even allow for procedural coding anymore (for instance in languages as Java, C++, C#, Python, and Ruby). Explaining OOP goes beyond the scope of this article, so for understanding OOP in PHP I'd like to point you in this direction. For now let's just say that OOP is about creating relatively small objects with specific functions that interact with each other to form a complete application, he explained.

According to Paul, the main advantages of OOP are:

  • Reusability of code; a well designed object has only one specific function and is therefore completely independent of the environment it is placed in and thus can be reused easily.
  • Clearer structure of code; again a well designed object has only one specific function which means that all the code supporting that function is located in one place which increase maintainability.

A major disadvantage of OOP is that it requires more lines of code and is therefore more time consuming to produce, he said.

In PHP we as developers are left with a choice. Typically, anyone who started out with PHP without any (OO) programming background will have started with learning procedural coding. Most tutorials on the web only cover procedural coding and quite honestly, the old fashioned way is just easier to use in many situations (for instance in small applications, or when you just start out with PHP), Paul added.

According to Paul, Object Oriented Programming in PHP is definitely the way to go for any serious PHP developer taking on serious projects. For the past 8 months my web development firm has been working on a huge project for a real estate agent. The application takes care of many aspects of the clients administration, publishes its information to multiple people (each with different clearances) and in multiple formats (web content, PDF, RTF). Using OOP in projects such as this is so incredibly superior over using procedural coding. Using OOP, we for instance model a real estate object (a house...) as a PHP object. The (PHP) object contains over 60 variables (all stored in a MySQL database but intelligently retrieved by the object) and many functions that allow the object to update it's data and return information on itself based on the users clearance levels. The data itself can be interpreted by either our web content generator object, or by our PDF generator object, no changes required. This goes for all the little parts the application has and you wouldn't believe how much time it has saved us in making small adjustments and adding small new features.

Doing this project in procedural code would have been horrible and messy. Just imagine having new additions to your project specifications on a weekly basis for several months and jotting all those things in between the already existing code using if/else statements etc. in procedural coding. You would probably go screaming mad about the PHP files containing more than 500 lines of code without any clear structure in them, he stated.

 

Read the Article

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use