Originally Posted by KULP
...I've googled this question and it seems I'm getting a lot of people asking "Procedural vs oop" and I find that completely bogus. I believe each method is used to solve different problems, and so this isn't a question asking for a comparison, but I'm rather trying to grasp when I would use one over the other. Thanks!
Yeah, people are fighting the wrong battle there , its NOT a question of proc vs
OO in PHP since neither is better than the other at any particular task and its pointless to even compare them that way.
e.g. there is no
single task (that I am aware of) that OO can do that procedural can not (apart from the obvious OO related stuff like reflection etc which you wont need unless you are using OO in the first place)
The only time that one may appear 'better' than the other is when you start to scale, at that point OO code is probably easier to manage but procedural code will have the edge on speed (ignoring external optimization)
The real question is which OO ? I use OO a lot in PHP, but Fou-Lou might not call my code 'true' OO, more a collection of objects that sometimes talk to each other..
I might look at Fou-Lou's code and (with ALL RESPECT) suggest that his approach seems better suited to Java than to PHP and that the overhead of a Java type implementation in PHP defeats the purpose of using PHP in the first place.
+I am not a fan of MVC as applied to the simple web.
So there are all different levels of OO usage in PHP, from
- procedural no objects,
- procedural code using PHP' built in OO interface for some functionality (mysqli etc)
- procedural code using some home grown objects for specific tasks
- my style of ...all OO but not as Java would know it
- the full MVC Java-stack style stuff
and there are probably many levels in between !
Many will say that this is confusing, they are not wrong, but its a trade-off of initial confusion over the incredible flexibility that PHP affords, and for that purpose suits me down to the ground.