This is a basic website. Based on the answers here, I do this:
private $db; public function __construct($id = null) { $this->db = Db::getInstance();
But if there is a static method, I cannot use an object-specific variable.
Is there anything better than manually specifying a db variable inside a static method?
public static function someFunction($theID){ $db = Db::getInstance();
EDIT: creating a static variable does not solve the problem. Access to undeclared static property . I still have to assign a variable in a static function. The question is, asks if there is a way around this.
My DB class (although this is not important for this discussion):
class Db { private static $m_pInstance; private function __construct() { ... } public static function getInstance(){ if (!self::$m_pInstance) self::$m_pInstance = new Db(); return self::$m_pInstance; }
}
source share