Re: define() or $variable for application settings?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>"Matt Arnilo S. Baluyos (Mailing Lists)" <matt.baluyos.lists@xxxxxxxxx> 
>wrote in message
>
>I have a config.inc.php file which basically contains all the
>configuration info that the applications needs (directory/file
>locations, database credentials, etc). The information there is set
>using the define() function.
>
>However, I've seen some open-source projects which either use
>$variables or associative arrays to save the values.
>
>My application works pretty fine but I'd like to solicit opinions from
>everyone on what they are using in this case. Also, I have plans of
>putting up a sort of coding guidelines for the company so it might
>help to have other opinions on this one.

Another option you can use is to create a "Config" class, and place all your 
configuration state in it. This is probably the slowest, but easy to code 
with.
class Config
{
function Username()
{
    return "Snoopy";
}
function Password()
{
    return "Secret";
}
};
This class is accessible anywhere, and your newer editors assist you -- type 
"Config::" and you get a list of all your available configuration values.
It also makes it easy to have a configuration value that depends on state 
(like "Debug", depends on which machine or folder it is running from).

I also have a class called "Settings" that are user-configurable within the 
website admin page.  All settings are placed inside a table, and the user 
can monkey with them at there will.  Settings::GetValue("Color") returns the 
user-defined value from the table.

Just some thoughts
DanB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux