OOP PHP What are the benefits? | Comments (2)
Posted in Code on 25th January 2005, 2:17 am by Stuart
Over Here at Sitepoint Harry Fuecks has kicked off an interesting discussion regarding the speed of OOP PHP versus procedural code.
What this exactly means requires qualification, as this would imply that speed of execution and speed of development are both to be taken into account to be fair. What I have found since using OOP PHP in web development is; where you are looking to create something that can be easily re-used, adapted/extended and improved, then OOP is the way to go.
Procedural code can be messy and hard to adapt later on. I currently work within a team of several developers where on occasion I have to modify other developer’s code. It’s usually the scripts which have utilised classes which can be quickly understood and changes be made without having to spend too much picking apart the code line by line to understand the flow.
I see OOP php as being similar to the way that using XHTML and CSS allows separation of structure and look from content; except OOP PHP separates functionality from implementation.
I will be watching this debate with interest to see the outcome of Harry Fueck’s OOP/Procedural comparision

I don’t really think there’s much of a debate to be had. Like the “how old a browser should you support” arguments, how heavily you value extensibility over performance depends almost entirely on what kind of application you are writing, who you expect to use it, and how often you anticipate changes. If you are making a very stable, high-traffic project, clearly you are going to want to lean towards speed and performance. But in my experience most PHP apps are intended for small audiences who’s needs are either rapidly changing or poorly defined — thus making on-the-fly changes more important.
Whenever I work on an app, I ask myself how many people are going to be using it and how often. If one or both of those numbers are small, I always lean towards OOP-style coding, just because it is easier to maintain and my audience won’t notice a fifty millisecond slowdown.
The key point you make is a valid one in that, this whole thing means different things to different people. My own view on the whole thing certainly relates more to practical usage than any concerns about speed of execution. For me, repetitive tasks are best done with classes and now that I use classes I won’t be going back.