class KnivesModel {
private $db;
public function __construct($dsn, $user, $pass){
try{
$this->$db = new PDO($dsn, $user, $pass);
}catch(PDOException $e){
var_dump($e);
};
}; // __construct
}
这段代码破坏了我的应用程序。我甚至还没有实例化这个类。我所做的就是将这个类包含在index.php中,然后"app"就会出现500个错误。有什么问题吗?
在try catch
和__construct
函数的末尾不应有;
删除构造函数声明和try/catch
块末尾的;
:
class KnivesModel {
private $db;
public function __construct($dsn, $user, $pass){
try{
$this->$db = new PDO($dsn, $user, $pass);
}catch(PDOException $e){
var_dump($e);
} // <<< Right here
} // <<< Right here
}