傳統式 PHP Debug 方式:
方式一:
於PHP檔案開頭加入下面兩行
error_reporting(E_ALL);
ini_set('display_errors', 1);
方式二:
php.ini 調整參數
error_reporting = E_ALL ;
display_errors = On;
※注意上面debug模式只限用於開發環境上,在正式環境上需要註解掉,避免於前端顯示錯誤訊息造成安全性上的問題。
補充說明:
error_reporting 可以設置參數有下面幾種
E_ALL : 是指全部的錯誤訊息都記錄
E_ERROR: 嚴重錯誤使得程式當掉都記錄下來
E_WARNING : 將警告訊息記錄下來
E_PARSE : 編譯時產生錯誤記錄下來
E_NOTICE : 運行中的程式可能會出錯的訊息
官網上的範例
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
參考網站:
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/errorfunc.constants.php
https://www.puritys.me/docs-blog/article-50-php.ini-%E8%A8%AD%E5%AE%9A%E8%A9%B3%E8%A7%A3.html