I hope I don't get in trouble for posting so much the past couple days, I'm not trying to dilute the boards. This just happens to be the best php forum I've found, and I'm in school getting my BS in interactive media. I'm doing a lot of coding lately, and trying to learn as fast as I can. So, I figure if I start my senior project now, I've got a three year head start on everybody else, muahaha.
Anywho... Right now my site is pretty small and probably doesn't need OOP, however I like the organization structure and feel that it gives me, so I'm trying to utilize it right now, and build based on that structure.
What I'm wondering at the moment, is the best way to avoid code repetition. I currently have three classes for my administrative backend, 'blog', 'gallery' and 'support'. I have certain code, (a buildURL() function and a paginate() function for example) along with opening a database connection that is part of all three classes. I want to centralize this, so what might be better?
Option 1) Create a fourth class, 'database' which would do all the db queries and basic functions, so two classes are created per page, $database = new database(); $support = new support(); for example, where $support->functions() could call $database->functions().
Option 2) Create a parent class, 'admin' or whatever, and create child classes (class support extends admin)? I haven't tried this yet, so I'm not entirely sure how much more effective it is or what benefits I get from it.
After playing around with this for a few days, I decided to go parent::child with my classes. It seems to be working well so far and allows me to include a central configuration layer in my parent class as well, which solves another problem I was having with my include structure.