Welcome to WebmasterWorld Guest from 22.214.171.124
While researching ways to streamline my work flow (rapid dev strategies, maximizing code re-usability, etc) I keep coming across commentary which essentially says that creating PHP web applications via OOP is the way to go.
At this point in my learning curve, I only consider myself a half-step above an apprentice and the whole OOP thing scares me. But, for the sake of being more efficient in my workflow, I'm willing to take the plunge (atleast get my feet wet) if the good and very knowlegable folks on this list are in agreement - and if learning this aspect of PHP would really speed up the dev of future projects.
So, what's the consensus here? Do most of the advanced developers here (or world-wide) use PHP/OOP strategies when developing their web applications?
This all depends on what you are trying to do. The topic of procedural versus oject-oriented programming is a big one that is hard to answer. There are major advantages to using both.
Procedural is written quickly and usually performs much faster. On the other hand, OOP makes it easier to maintain, distribute, and extend.
"The argument for object oriented programming is all about extensibility and packaging. Simply writing in an object oriented way won't document your code for you, but it may encourage you to document it. And, for purposes of extensibility, you may find yourself writing an API."
I myself would say that I generally am a precedural programmer, however, I do use OOP when it will make my life easier.
If you are going to use a lot of OOP, I suggest (if you haven't already) upgrading to PHP 5.
Anyway, I hope this has explained a little. Good luck!
All my work so far has been procedural and works fine (generally) but my problem lies in the fact that my development is sooooo sloooow and tedious.
I posted a topic here a few weeks ago about rapid dev strategies and a number of people - maybe even yourself - weighed in on my question and spoke of using frameworks etc to be able to reuse most basic elements of a site's code (i.e. nav elements, headers/footers, validation routines, etc) I'm very interested in doing this so I can accomplish more work and thereby (hopefully) heighten my rather megar lifestyle.
But when I looked at a number of these frameworks (fusebox, seagull, etc) my head started to swim - as is frequenly the case when I'm looking at someone elses code (unless it's quite simple). Accordingly, I've found that the best way that I can understand what is going on is to do it myself.
Even though that'll take MORE time, atleast I'll be confident in knowing what's happening and why and I've heightened my own "expertise" as well.
So... such is the reason I'm asking about OOP aspects of PHP: to essentially build my own resuable framework to use on various projects as well as reusable functions that I can do the same thing with.
That's the real background of my interest.
Thanks again for the link; I'm sure that after I read it most of my questions will be answered.
coopster: That is exactly the way I feel. I feel that by the time I find out how their code is working I could have written it myself, especially considering the tweeks I usually need to add for my particular situation.
> by including functions but classes allow more flexibility.
In my code, most everything is done by functions. I don't know if this qualifies as procedural or OO, but I'm having trouble envisioning how OO adds more flexibility. For example I use forms a lot. They usually take the form:
How would this look like with OO?
$mySelect = new select_tag();
I don't see the difference or I must be missing something.
Also I program actionscript a lot (flash) and they must have a whole different notion of what an object is. In actionscript it is a really cool way to organize/store/manipulate data. You can add properties and methods easily, and that in my mind adds flexibility and beats the pants off of arrays for complexity of data organization. I often import xml and create an object that essentially mimics the xml.
But in php I can do this (or can I):
$form_data = new Object();
$form_data->name = "tom";
$form_data->date = "never";
Is there a basic (non-class) Object() in php?
Using a class offers flexibility in that you can reuse everything in the class by extending it when necessary. The "standard" code remains the same all the time so by placing it in a class you can reuse the code. Take database access for example. You run the same functions all the time so by placing them in a class you can reuse this class over and over again, even across domains that are running on the same server by reusing the same code in that class. However, each domain has a different database with different login credentials. All you have to do is extend your class and you setup a single script to handle that part for you. You invoke this extended class throughout your site pages. Maybe this is not the best example, but you get the picture. You can also override functions in extended classes. So, if you need to redefine a function on the fly for a certain site but wanted to use the same group of functions you are going to get errors unless you were extending that function in a class.