Re: Discussion of method -- config files

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

 



On Thu, Jun 19, 2008 at 10:04 AM, tedd <tedd@xxxxxxxxxxxx> wrote:
> Hi gang:
>
> More of a question of method rather than of "right" or "wrong" -- of the two
> methods mentioned here, which way would be "better" and why?
>
> 1. Setting $GLOBALS one time as shown here.
>
> At 12:23 AM -0400 6/19/08, Robert Cummings wrote:
>>
>> And the variables are defined in config.php
>>
>> --------------
>> config.php
>> --------------
>> <?php
>>
>> //Mysql vars
>> $GLOBALS['mysql_host'] = "localhost";
>> $GLOBALS['mysql_user'] = "user@localhost";
>> $GLOBALS['mysql_pass'] = "";
>>
>> ?>
>
>
> 2. Or, setting variables as shown below and including them when needed?
>
> --------------
> config.php
> --------------
> <?php
>
> //Mysql vars
> $localhost = 'localhost';
> $mysql_user = 'user@localhost';
> $mysql_pass = '';
>
> ?>
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I use a static class for my config.  I know using an array would be
faster but I need to have consistency between the projects.

An example would be:

$_cfg = array(
    'local.writable.path'   => $localPath .'writable/',
    'local.template.path'   => $localPath .'templates/',
    'root'                  => '/'
);
...
$_cfg['fck.editor.url']     = $_cfg['currentHost'].'lib/FCKEditor/';
$_cfg['fck.config']         = $_cfg['currentHost'].'lib/FCKEditor/';
$_cfg['fck.config.js.url']  = $_cfg['currentHost'].'fckconfig.js.php';

blah_Config::setMany($_cfg);

Then

$root = blah_Config::get('root');


Out of the two methods that you described, I would go with the
$GLOBALS.  Although I would make sure to put my config into a separate
array so that there is less chance of collisions.  The reason I would
use the globals array is because it is very obvious that you are using
a global variable that came from somewhere else.  Plus there is a much
smaller chance that you will create a $GLOBALS entry for a temp
variable that would overwrite your $db_host variable.

$GLOBALS['config']['db_host'] = 'localhost';

If it is only you working on your project never using any outside code
it really doesn't matter though.

-- 
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