I'm new of the forum but I would like to ask you a few questions: if this is not the right section... blame me!
I've got two blocks of OOP code, that can do the same tasks, in just a (bit) different way.
Singleton pattern
Code: Select all
class MYSQL {
static private $instance = NULL;
static function getInstance()
{
if (!self::$instance instanceof self)
{
self::$instance = new self;
}
return self::$instance;
}
function conn ($_HOST, $DB_USER, $DB_PASS)
{
mysql_connect($_HOST, $_DB_USER, $_DB_PASSWD) or die("You dummy coder!");
}
private function __construct ()
{
...
}
private function __clone ()
{
...
}
}
MYSQL::getInstance()->connect(...);
The I Don't Know pattern
Code: Select all
class MYSQL {
function conn ($_HOST, $DB_USER, $DB_PASS)
{
mysql_connect($_HOST, $_DB_USER, $_DB_PASSWD) or die("You dummy coder!");
}
private function __construct ()
{
...
}
private function __clone ()
{
...
}
}
MYSQL::connect(...);
Any idea about the difference between these 2 patterns?
I think that probably script's security is involved...but...i truly don't know...