View Single Post
Old 07-15-2008, 06:35 PM   #20 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Static methods are awesome. But not really needed in this case drewbee
That depends. If you only need only one connection to the database (you usually don't need more than one), then a singleton could be implemented:

PHP Code:
class XYZ
{
     protected static 
$instance null;
     
     public static function 
getInstance()
     {
         if(
self::$instance instanceof self === falseself::$instance = new self();

         return 
self::$instance;
     }

     private function 
__construct() { }

     private function 
__clone() { }

That way, you can't clone or create multiple instances of the same object. But again, that depends, there are cases when you need a clone of the db object (e.g.: nested fetching), and in that case it's better if you leave out the implementation of the magic clone method.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote