Question: All the singleton patterns I have seen use a reference to the object to determine if the object has been instantiated. However, if I am using a singleton to guarantee only one db connection, why not use the db connection resource link to do this? Here is the code I am using. (PS: it works fine). I use the comment to be able to search for my classes easily. 

```
/*one*/

class one
  {
  public static $db;
  private function __construct()
    {
    self::$db=new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
    }
  public static function get()
    {
    if(self::$db==NULL)
      {
      new self();
      }
    return self::$db;
    }
  }

```

Answer: 
In PHP, a constructor does not return.

So your `get` method returns a `one` object, the first time it's called, then a `mysqli` object. Probably not what you want.

```
if( self::$_db == NULL )
{
    return new self(); // Here you return an object of class one
}
else
{
    return self::$_db; // Here you return an object of type mysqli
}

```

If you want to return the `mysqli` object, you do not need a singleton, as there is no need to create an instance of an object that's only here to return an instance of another object.

The registry pattern would be better in such a case.

If you need to provide methods (a wrapper for your DB object), then create a real singleton.

**EDIT**

I checked your updated code.
Now you return always the `mysqli` instance. But you do not need to instantiate your own object. That's completely useless...

If you really want to go with your kind of pattern, as golden said, in your static instance, checks if `self::db` is `NULL`. If yes, creates the `mysqli` instance, and assign it to `self::db`. Then returns it.

```
public static getDatabaseInstance()
{
    if( self::$_db == NULL )
    {
        self::$_db = new mysqli( ... );
    }

    return self::$_db;
}

```

Also set the constructor private, so users won't be able to create useless instances of your class. Or better make it public and throw an exception:

```
public function __construct()
{
    throw new Exception( 'This class is not supposed to be instantiated' );
}

```
As Macmade already pointed out, the `constructor` method doesn't return anything but an instance of the class. Assuming you always want the same instance of `mysqli`, here's how I'd do it.

```
class DBInstance
{
    protected static $db;

    private function __construct()
    {
        // intentionally empty
    }

    public static function get()
    {
        if(self::$db === NULL)
        {
            self::$db=new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
        }

        return self::$db;
    }
}

```

It most certainly is a singleton pattern with an added bonus of separating instantiation from the instantiated class.