当我尝试创建我的班级的新实例时,我遇到了错误。
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");
我收到错误:
方法 MyClass::__get() 必须恰好采用 1 个参数
我尝试添加不带任何参数的访问器:
public function __get()
{
return $this;
}
但我仍然收到这个错误。