Originally posted by Crowley
Just wanna know, how much do you use objects in generating pages?
I've just started using PHP and I've seen some weird sample code where HTML templates get parsed by PHP objects which then outputs the HTML.
It al just looks a bit overcomplicated to me...
Is there any good reasons to use a lot of objects in PHP pages? What I mean to say is: can I use my object created in one page on another?
I may as well answer this one for Russ. He is busy fighting with his overheating graphics card.
We use objects in PHP for the sake of neat code. One example is that we have a "Player" object. When the object is created, it retrieves a bunch of information about a player, eg. rating, games player etc... and we create some functions to access this information. As you would expect, some of the info will be cached on creation, other info will be calculated as required.
However, the object is entirely stateless between HTTP requests. That is, it has to be created anew each time. So, unlike something fancy like a Java Web Application Server which can keep objects persistent, out object use is purely for code clarity, maintainability and data encapsulation.
The stuff you mention about templates sounds like someone has created some static HTML pages which are then being enhanced by PHP before being sent to the browser. It sounds like the templates in your examples are simply preventing the HTML being hardcoded in the PHP code. Which is quite a neat way of doing things.
Hope this helps a little...