Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
This is a topic I was thinking about and wondered what the you guys thought. I have used a couple of different ways to list things like DB addresses passwords etc and started thinking which was the better/most common/prefered way to do it.
You cannot use a class level variable using Config::database_host directly without creating an object unless you declare it static. Further, creating constants will help you save variable memory space.
Other methods of configuring your application could be an XML file that would store name/value pairs. But then special care should be taken that your XML file is secure.
The best place to do it (from what I've found) is in a config file that is included.
Globals cannot be unset, so are available in absolutely any script that includes the global-defining script.
Storing them in public config variables means they'll be outputed if the object is displayed. Make them private & they should be ok.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
pickle wrote:The best place to do it (from what I've found) is in a config file that is included.
Globals cannot be unset, so are available in absolutely any script that includes the global-defining script.
Storing them in public config variables means they'll be outputed if the object is displayed. Make them private & they should be ok.
uh?! I think you are very very mistaken...or maybe I didn't get something
1. globals is a baaad thingy...I don't see how cannot be unset, even if so..they can be overwritten - with wrong values
2. public config variables....output if object displayed?! how will private help in this way....
pickle wrote:The best place to do it (from what I've found) is in a config file that is included.
Globals cannot be unset, so are available in absolutely any script that includes the global-defining script.
Storing them in public config variables means they'll be outputed if the object is displayed. Make them private & they should be ok.
uh?! I think you are very very mistaken...or maybe I didn't get something
1. globals is a baaad thingy...I don't see how cannot be unset, even if so..they can be overwritten - with wrong values
2. public config variables....output if object displayed?! how will private help in this way....
Whoops
1) I mis-typed here. I meant constants, not globals. Variables you set with define() cannot have their value set & are available anywhere.
2) I assumed that when you declare an object variable private, it's value wouldn't be output when calling print_r() or var_dump(). I was evidently wrong.
Thanks for pointing out the mistakes there.
Nonetheless, my initial point is still valid - the best place to put it is in a config file that is included.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I use a Config class and make it available via a Registry. That way the interface is consistent, but the source of the config data can be in any format or multiple formats.