does anyone have an idea how to solve that?
Expand|Select|Wrap|Line Numbers
- 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
- }
Expand|Select|Wrap|Line Numbers
- 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
- }
- }