class ConnectionFactory
{
private static $factory;
public static function getFactory()
{
if (!self::$factory)
self::$factory = new ConnectionFactory(...);
return self::$factory;
}
private $db;
public function getConnection() {
if (!$db)
$db = new PDO(...);
return $db;
}
}
function getSomething()
{
$conn = ConnectionFactory::getFactory()->getConnection();
.
.
.
}
There are a couple of things that i dont get
- Am i right when i say "staic property of a class can be accessed without initiating the class"
- what does
!db
do - How is this happening
ConnectionFactory::getFactory()->getConnection();
- Could somebody explain
getFactory
method