Re: Opinion about the using $GLOBALS directly

From: Date: Wed, 19 Dec 2007 14:07:11 +0000
Subject: Re: Opinion about the using $GLOBALS directly
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-266071@lists.php.net to get a copy of this message
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 <jochem@iamjochem.com> 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 >> >>

« previous php.general (#266071) next »