2013-08-04 34 views
2

我正在寫一個應用程序,我認爲所有的錯誤都在處理中,包括致命錯誤。這是一個不可捕捉的致命錯誤?

但是現在我發現了一個導致白屏的錯誤,並且錯誤只出現在Web服務器日誌中。

$nonExistentVar + 1; // Notice error, gets caught and pretty error is displayed 

$existentVar->nonExistentMethod(); // Fatal error, gets caught and pretty error is displayed 

$nonExistentVar->nonExistentMethod(); // White screen, error can be seen in nginx.error.log 

是最後一個錯誤抓不到?或者問題是什麼?

我正在使用Silex,不確定是否重要。

+0

'如果($ nonExistentVar-> nonExistentMethod ())//錯誤'? (還有,你的日誌文件報告的錯誤是什麼?) – Alfie

+1

忘了添加..如果你正在運行該腳本就像張貼和第2行導致致命錯誤,第3行不會運行 – Alfie

+0

你如何處理錯誤? – goat

回答

0

我瞭解它的方式,可以捕獲異常,但致命錯誤不能。我很想知道你是如何'捕捉'例2中的致命錯誤的?

爲什麼不嘗試使用php is_a()測試來試圖調用該方法之前$ nonExistentVar是否是正確的類?或者可能與method_exists()一起使用,如果您仍不知道某個班級是否有可用的給定方法。

+1

他使用Silex(使用Symfony組件,包括'Debug'),並且它並不完全捕獲錯誤,[調試組件](http://silex.sensiolabs.org/doc/cookbook/error_handler.html #handling-fatal-errors)使用php'set_error_handler'發送相當的響應。 – dezull

0

嘗試將只有最後一行:

$nonExistentVar->nonExistentMethod(); 

這對我的作品,作爲Symfony\Component\Debug\ExceptionHandler在遇到立即發送響應第一Error

public function handle(\Exception $exception) 
{ 
    if (class_exists('Symfony\Component\HttpFoundation\Response')) { 
     $this->createResponse($exception)->send(); 
    } else { 
     $this->sendPhpResponse($exception); 
    } 
}