从静态方法访问非静态属性
class database{
protected $db;
protected function connect(){
$this->db = new mysqli( /* DB info */ ); // Connecting to a database
}
}
class example extends database{
public function __construct(){
$this->connect();
}
public static function doQuery(){
$query = $this->db->query("theQuery"); // Not working.
$query = self::$db->query("theQuery"); // Not working.
$query = parent::$db->query("theQuery"); // Also not working.
}
}
我想做这样的事情,但我找不到一种可行的方法,财产必须静态...