0
當我試圖創建我的類的新實例時,我得到錯誤。方法MyClass :: __ get()必須採用1個參數
class MyClass
{
public $link;
public function __construct()
{
$this->Connect();
}
private function Connect()
{
$db_host = DB_HOST; // defined in included file
$db_name = DB_NAME; // defined in included file
$this->link = new PDO("mysql:host=$db_host;dbname=$db_name;charset=UTF-8", DB_USER, DB_PASSWORD);
$this->link->setAttribute(PDO::ATTR_AUTOCOMMIT,FALSE);
}
// other methods here
// there is no custom __get() method
}
我試着去創造新的實例,並使用的方法之一:
include "inc/myclass.php";
$db = new MyClass();
$db->InsertPost("2012-01-01 10:00", "Test content", "Test title");
即時得到錯誤:
Method MyClass::__get() must take exactly 1 argument
我想不帶任何參數添加訪問:
public function __get()
{
return $this;
}
但我仍然得到這個錯誤。