please reply to the list ...

js 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 ];
}

> 
> On Dec 19, 2007 9:52 PM, Jochem Maas <[EMAIL PROTECTED]> wrote:
>> Sancar Saran schreef:
>>> Hello list.
>>>
>>> I want know  to you opinions about using $GLOBALS directly.
>>>
>>> like
>>>
>>> $GLOBALS['myString'] = 'test';
>>> $GLOBALS['myArray']['this'] = 'this';
>>> $GLOBALS['myArray']['that'] = 'that';
>>> $GLOBALS['myClassObj] = new SomeClass;
>> there is no real difference between 'global $foo' and $GLOBALS['foo'],
>> and the second is probably more maintainance friendly (as Rob pionted out)
>>
>> that said, avoid globals like the plague - sometimes you may come up with
>> a situation where using a global is really necessary - such situations should
>> be the exception rather than the rule, often if your thinking of using a
>> global there is another way of doing it. jmho
>>
>>
>>> Regards
>>>
>>> Sancar
>>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

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

Reply via email to