Re: Opinion about the using $GLOBALS directly
| From: | Jochem Maas | Date: | Wed, 19 Dec 2007 15:20:12 +0000 |
| Subject: | Re: Opinion about the using $GLOBALS directly | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-266090@lists.php.net to get a copy of this message | ||
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 :-)
>