Re: Opinion about the using $GLOBALS directly

From: Date: Wed, 19 Dec 2007 14:31:45 +0000
Subject: Re: Opinion about the using $GLOBALS directly
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-266082@lists.php.net to get a copy of this message
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. -- Richard Heyes http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support ** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

« previous php.general (#266082) next »