[PLUG] PHP OOP Programming question

gilmanhunt at comcast.net gilmanhunt at comcast.net
Thu Jun 3 20:49:01 UTC 2004


I'd consider myself an above-average PHP programmer (waits for the laughter to die down) but I haven't done a lot of OOP programming. I've done some basic stuff- making classes, methods and properties, and used them with some success. What I'm trying to say, is I'm familiar with the basics of OOP Programming in PHP. 

However, I'm working on a fairly large project, and I think it'd be great to use classes for it. In contemplating the "structure" of these classes, I have a question.

If I make a db_access class, with you know, queries, return values, connections to the db server, etc.
And I make a "tasks" class with deadlines, tasks, id numbers, etc, what is the approved way to have tasks use the database. Should make a base class that includes the db stuff, and then extend it for various other classes, should I instance that db class when I instance the other classes 

i mean this:
class Foo(){
  var bar;
  function Foo(){
   $this->bar = new db_class;
 }
}

These ways seem fairly weighty to swing around when I instance code, and it seems like I'd have a lot of extra connections to the database.

Any suggestions/best practivces?

-Russ




More information about the PLUG mailing list