构造函数打破应用程序没有类实例化

构造函数打破应用程序没有类实例化

问题描述:

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中,并且“应用程序”爆发了500个错误。有什么问题?构造函数打破应用程序没有类实例化

+0

启用'的error_reporting ='或至少期待到Web服务器'error.log' – mario

try catch__construct函数的结尾应该没有;

+0

非常感谢您! :d –

取出;在构造函数声明和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 

}