[nycphp-talk] Object Oriented Question
adam at ecamp.net
Fri Jun 7 11:07:16 EDT 2002
I generally use php classes for all my code, but mostly centered around
an OO design from the UI and second logic, especially for pages like
I would have a class gamesite with all my base functions that would be
use. User authentication, emails, voting functions etc... and if you
don't have that many feature you can keep everything in this one class.
Or if you have multiple sections, you can create different classes that
extend this one to keep things separate and neat.
So you can have something like in index.php
$page->init(); //start session, whatever else u do every page
$page->checkLogin(); // checks to see if user is logged in, if not
$page->buildTop(); //builds top nav
$page->processForms(); //process any forms that may have been submitted
before displaying content
$page->showGameReview(); // here you can do that example you were
and then inside class gamesite, you can build functions that these
master functions call... but this generally keeps things a little more
organized than complete top down programming I suppose. PHP isn't C++
or Python, where it takes a lot more effort in some cases to really OO
I find having a few base classes is nice and I just extend upon them,
using functions I've had for years as if they are native php I'm so used
If you check out http://madhive.com it was done all PHP OO over the
past few years. Site is a bit slow most likely because of lack of
attention to the servers for months. The you login and notice the
content boxes on the right, those are all treated as separate php
objects throughout the users session and move from page to page. Their
functionality is nicer throughout the site. As well as skin color
changes, and other preferences. The OO method made changing these things
From: ophir prusak [mailto:prutwo at onebox.com]
Sent: Friday, June 07, 2002 10:48 AM
To: NYPHP Talk
Subject: [nycphp-talk] Object Oriented Question
I've decided to clean up the code on my site, and at the same time use
object oriented code.
I have a few ideas in my head, but I really wanted to get some input
from others that have built projects in PHP using OO code.
Here's the problem I'm currently trying to solve (I've simplified it
a bit and left out un-necessary details).
My site is a video game site. Currently, my database has:
A games table which has basic game information for each game (game_id,
title, console, etc)
A reviews table which has game_id (foreign key to games table), review
date, review text, reviewer name and email.
If you look at this URL
you can see a page which shows a list of all the games and the date for
the most recent review for that game.
Currently I'm just doing this with a single SQL query (simple join of
the two tables) and echoing out the results.
I'm trying to envision how to create this page using object oriented
My initial thought was to somehow use a game object, but if I have to
instantiate a game object for every game, this seems like it would have
an enormous amount of overhead and be slow.
How is this usually done on OO projects ?
Am I missing something or would you say that if your data sits in a
database and your doing a search or mass listing of data then OO code
is not the way to go.
prutwo at onebox.com | http://www.prusak.com/
More information about the talk