I was wondering which would be better to use. This is considering that the only thing I want to call (for now) is the Database Connection.
Static DB - Singleton PDO connection.
class a
{
public function __construct()
{
// Getting the connection for a random class,
// This would be an obscure class not part of the flow of the system
// Which is hard to explain, maybe AJAX type stuff.
$this->DB = DB::Connect();
}
}
Registry - Referenced non-static Singleton PDO.
class a
{
public function __construct()
{
// Getting the connection for a random class,
// This would be an obscure class not part of the flow of the system
// Which is hard to explain, maybe AJAX type stuff.
// Assuming Registry was already Set
$this->DB = Registry::Get('DB');
}
}
I know you can statically call the PDO but I want a DB object to handle the connection and quite a few other things.
Question about a Registry:
Do I need to return the DB object as a reference inside the registry? Because I thought all objects were passed as reference by default… So
function &connection($link)
{
return $link;
}
Is that useless?