Re: Function to load vars in PHP?
You are beginning to get into enterprise application design.
You realise that "Global" variables are bad design and should be avoided.
So what to do?
There are two schools of thought as to how to handle global variables.
1) Store all global variables in an object that holds an array of objects and an array of variables. (a registry)
You can then pass this object to each function that needs its (dependency injection) or you can create a global registry.
The registry should contain all your applications global variables and be passed from one object to another.
Don't be tempted to create the registry as a singelton otherwise you might as well use $_global['key']=$somevar.
2) use the global super array for what it was intended to do. $_global['my_var'] = $my_var.
The java/php oop purists will tell you that global variables are evil, and they are, but there are multiple ways of passing a single object that "contain" these "evil" variables. The bottom line is to use what you feel comfortable using.
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Last edited by Easywebdev : 03-24-2008 at 01:00 AM.
|