It's a basic website. Based off answers on here, I'm doing this:
private $db;
public function __construct($id = null) {
$this->db = Db::getInstance(); //singleton from the Db class
But if there is a static method, I can't use the object specific variable.
Is there anything better than having to manually specify the db variable inside the static method?
public static function someFunction($theID){
$db = Db::getInstance();
EDIT: Making the variable static doesn't solve the problem. Access to undeclared static property
. I'd still have to assign the variable within the static function. The question is asking if there's a way around this.
My DB Class (although not important to 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;
}
}