View Single Post
Old 09-30-2007, 04:56 PM   #3 (permalink)
jordie
The Wanderer
 
Join Date: Sep 2007
Location: Sydney, Australia
Posts: 19
Thanks: 0
jordie is on a distinguished road
Default

Quote:
Originally Posted by Karl View Post
Have you considered using "static classes"? These are great when you know that you do not need to create instances of a class, for example, a Session class.

In OOP however, I tend not to create too many globally declared functions/variables, so I personally don't run into this problem. For example, each "page" can be expressed as a Class. Seeing as each page is a "page", we can wrap all our page related data inside this class, we can then give access to common objects (as properties) inside the Page class.

So let's say I added myFunction() to my LoginPage class, I can simply access common objects though the page's properites, such as $this->m_pMyObject->doSomething();
Ah ha yes, but as far as I know that requires PHP 5, yes? Our current minimum requirements are PHP 4.3, and I seriously had to push to get that far. (Previously it was 4.1) I would absolutely love to put our requirements at PHP 5.2, but that would alienate a major portion of our current and potential market, so thats not an available option. :( We really have to wait until a majority of hosts (shared hosts) provide PHP5 by default.

So I'm kind of limited here. I would love to go all php5 on this app (which is a CMS of sorts), but its just not possible. :(

Quote:
Originally Posted by Karl View Post
It's a different pattern to development, and I guess you really can't switch over this late into it? I would seriously suggest the use of static classes over global variables, infact, you should aim to cut down on the number of globally defined variables and functions in your script, this is one of the places where OOP should shine.
Since I've taken over this project a while ago I've been reducing them as much as I can, and reducing the dependencies on each other as much as possible also. I've lowered the memory usage significantly, and I'm thinking if I change to the &GetClass() method I can reduce it even further.

Currently all classes are included, defined and initialized even if they're not needed by that certain page request. This is obviously rather stupid. :( So I'm thinking if I change to the &GetClass() idea each class will only be included, defined and initialized when they are actually needed, while still keeping them global in some respect.

Another pain is the template system which uses a class for each section. For example, A class for PageHeader , a class for "RecentNews", a class for "CategoryMenu". It seems like a bit of overkill, but then these classes also reference the core classes. E.g. the "ViewPage" template class will want to use the core page class, but so will the "PagesMenu" so it know what the current page is. So this means the core class, after being initialized, needs to be globally available as many different template classes may want to reference it.

I'm looking at writing a new template system, which I'd love to get more opinions on, but I'll make a separate post another time as it'll take a little while to explain. But this one wouldn't be so OOP, as I don't think it really needs to be.
jordie is offline  
Reply With Quote