Php 构造函数在没有类实例化的情况下中断应用程序
这个代码破坏了我的应用程序。我甚至还没有实例化这个类。我所做的就是在index.php中包含这个类,“应用程序”出现500个错误。有什么问题吗?应该没有Php 构造函数在没有类实例化的情况下中断应用程序,php,class,constructor,Php,Class,Constructor,这个代码破坏了我的应用程序。我甚至还没有实例化这个类。我所做的就是在index.php中包含这个类,“应用程序”出现500个错误。有什么问题吗?应该没有。删除在构造函数声明和try/catch块的末尾: class KnivesModel { private $db; public function __construct($dsn, $user, $pass){ try{ $this->$db = new PDO($dsn, $user, $pass);
在try catch
和\u构造
函数的末尾添加code>。删除代码>在构造函数声明和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);
};
}; // __construct
}
类针织模型{
私人$db;
公共函数构造($dsn、$user、$pass){
试一试{
$this->$db=新PDO($dsn,$user,$pass);
}捕获(PDO$e){
var_dump($e);
}//启用error\u reporting=
或至少查看Web服务器error.log
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
}