クラスの新しいインスタンスを作成しようとすると、エラーが発生します。
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;
}
しかし、私はまだこのエラーを取得しています。