Re: Opinion about the using $GLOBALS directly

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

 



Richard Heyes schreef:
>>> I always store database handler in $GLOBALS.
>>> I think that's the best place to save request-level-global.
>>> I wonder where other people save that kind of data.
>>
>> how about a static variable inside a function or a static member of a
>> class.
>>
>> e.g.
>>
>> function getDB($args) {
>>     static $conn = array();
>>
>>     $key = serialize($args);
>>     if (!isset($conn[ $key ])
>>         $conn[ $key ] = new DBConn($args);
>>
>>     return $conn[ $key ];
>> }
> 
> That's surprisingly similar to how I do it. Then it's a simple matter to
> call getDB() (which you can do no matter what the current scope is) to
> get the database object.

guess we agree on somethings :-)

> 

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