Re: Discussion of method -- config files

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

 



On Thu, 2008-06-19 at 10:04 -0400, tedd 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 = '';
> 
> ?>

These are sort-of the same... until you include the file from within a
function and you find that the latter style has not actually populated
the global variables, but rather ha populated local variables in the
containing function.

Having said that though, both are ugly. In practice I do the first but
using a second level of nesting. For instance:

$GLOBALS['interJinn']['mysql_host'] = "localhost";
$GLOBALS['interJinn']['mysql_user'] = "user@localhost";
$GLOBALS['interJinn']['mysql_pass'] = "";

That way at least the global space is only polluted by a single well
defined variable (unlikely someone else is using a variable named
interJinn ;)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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