I've got 2 DB classes (see below) where one class extends my base DB class. I want the child classes (the User class is just an example) to have the static method getInstance() but I can't declare this function abstract (E_STRICT) and I don't see, how I can implement an interface.
does anyone have an idea how to solve that?
does anyone have an idea how to solve that?
Code:
abstract class Base
{
private static $PDO = NULL;
private static $PS = array();
function __destruct()
{
self::$PDO = NULL;
}
protected static function load()
{
if (self::$PDO === NULL)
{
try {
$dsn = 'mysql:host=' . DB_SERVER . ';dbname=' . DB_NAME_2;
self::$PDO = new PDO($dsn, DB_USER, DB_PASS);
self::$DBstatus = 'connected';
}
catch (PDOException $pdo)
{
ErrorLog::logException($pdo, __CLASS__, __METHOD__);
}
}
}
// some more general and useful methods
}
Code:
class User extends Base
{
private static $instance = NULL;
function __construct() {}
function __clone() {}
# I want this function to be implemented
# by every child class of Base
# though not necessarily with the self::init() call
public static function getInstance()
{
if (self::$instance === NULL)
{
self::$instance = new self;
// this is where class specific code begins
self::init();
}
return self::$instance;
}
private static function init()
{
parent::load();
# prepare several statements
}
}
Comment