I have a class which I am going to make Singleton. For this reason, I want to use a trait. Something like this:
trait TSingleton
{
private static $instance = null;
private function __construct() {}
private function __clone() {}
private function __wakeup() {}
/**
* @return static
*/
public static function getInstance()
{
if (is_null(static::$instance)) {
static::$instance = new static();
}
return static::$instance;
}
}
And then:
class Db implements IDb
{
use TSingleton;
...
}
The question is if the Db's constructor would be private also, and if it does, why could I create its inheritors?