Please turn on javascript in your browser to play chess.
Developers Forum

Developers Forum

  1. Subscriber Crowley
    Not Aleister
    27 Jul '03 16:31
    Hey Russ

    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?
  2. Subscriber Chris
    Site Admin
    27 Jul '03 17:17
    Originally posted by Crowley
    Hey Russ

    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?
    Hi Crowley,

    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...
    Chris
  3. Subscriber Crowley
    Not Aleister
    27 Jul '03 20:43
    Cool, that's what I wanted to hear.
    Just thought you had some clever way of passing the objects around different pages.

    I'm busy with some of my own projects (just starting out with my own web ventures, using RHP as my inspiration - you guys have done a great job!)
    Because I've used PHP for some other of my projects at university, I thought I might as well try and learn it properly.

    The HTML templates are used as you said, but it just seems a bit overcomplicated, making changes just more work.