I began working on a PHP app before Christmas for a college project which was submitted and worked to a certain extent. The app was built with PHP and mySQL and I seperated all of the functions out into include files and just made calls from elsewhere. My question is on what architecture I should use for the new version?
I have decided to start fresh and need to know what types of architectures are best for stability, ease of use and portability. For example, my current architecture would’ve looked like this:
HTML -> PHP (includes) -> mySQL DB
I have heard some discussions on these forums saying to seperate out the HTML and PHP which I have tried to do. I’ve also read about using OO PHP and how that can increase the portability of code. So what does everyone think? Should I stick to the way it’s done or adapt the technologies and layers? Thanks a lot.
If you’re just learning OOP this might be a great excercise for you. Be advised however that the aamount of design time will increase for you as you really must conceptualize the entire app before writing any code.
ZEND, which produces the PHP engine, may move PHP to a more OOP paradigm in the future so it couldn’t hurt.
In any event, learning OOP is a plus for you.
I know some OO already as I’ve used Java in college but havent developed any enterprise level stuff with it. Also, what are the advantages if I use OO instead of standard functions in include files?
One caveat: PHP supports OOP “like” development, but it’s not full OOP.
By that I mean no multiple constructors in a class, only 1 per class in PHP.
Also, whereas in JAVA, an object reference is exactly that, a reference to an object, in PHP, if you want to reference an object you must explicitly say so, otherwise you’re working on a copy of the object. Thus there are some drawbacks to PHP OOP.
Benefits with PHP OOP are the same as with any other OOP:
Using functions and includes achieves a level of abstraction, however, functions don’t have the benefits of behavior as do Objects
Just some random thoughts.
Personally, I’ve tended more toward the includes/functions programming with PHP, though I include some classes: database connection class, application specific classes for the app. I may be working on. Mixing and matching sort of stuff, primarily due to PHP’s OOP shortcomings. Also, sometimes it’s just plain faster not to use an OOP approach.