2011-10-08 198 views
0
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

回答

2

try catch__construct函數的結尾應該沒有;

+0

非常感謝您! :d –

0

取出;在構造函數聲明和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 

} 
相關問題