php強制顯示錯誤 - php顯示錯誤
如何關閉PHP通知? (10)
你可以檢查這個常量是否已經使用:
<?php
if (!defined('MYCONST'))
define('MYCONST', 'Weeha!');
?>
Notice: Constant DIR_FS_CATALOG already defined
我已經在php.ini
註釋了display_errors
,但不起作用。
我如何讓PHP不向瀏覽器輸出這樣的東西?
UPDATE
我把display_errors = Off
放在那裡,但它仍然在報告這些通知,
這是PHP 5.3的問題嗎?
報告眾多的調用堆棧
你可以設置ini_set('display_errors',0);
在你的腳本中定義你想用error_reporting()
顯示哪些錯誤。
在代碼中使用此行
error_reporting(E_ALL ^ E_NOTICE);
我認為它對你完全滿意。
對於PHP代碼:
<?php
error_reporting(E_ALL & ~E_NOTICE);
對於php.ini
配置:
error_reporting = E_ALL & ~E_NOTICE
從PHP文檔( error_reporting ):
<?php
// Turn off all error reporting
error_reporting(0);
?>
該功能的其他有趣選項:
<?php
// 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
// This is the default value set in php.ini
error_reporting(E_ALL & ~E_NOTICE);
// For PHP < 5.3 use: 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);
?>
您可以將display_errors
設置為0
或使用error_reporting()
函數。
然而,通知令人討厭(我可以部分同情 ),但它們有助於達成目的。 你不應該定義一個常量兩次,第二次不會工作,常數將保持不變!
我最近發現了這個詭計。 在可能產生警告/錯誤的行的開頭敲擊@。
就像通過魔法一樣,它們消失了。
我相信在php.ini中註釋display_errors將不起作用,因為默認為On。 您必須將其設置為“關”。
不要忘記重新啟動Apache來應用配置更改。
另請注意,儘管可以在運行時設置display_errors,但在此處更改並不會影響FATAL錯誤。
正如其他人所指出的,理想情況下在開發過程中,您應該盡可能以最高級別運行error_reporting並啟用display_errors。 雖然第一次出發時很煩人,但這些錯誤,警告,通知和嚴格的編碼建議都會加起來,使您成為更好的編碼器。
通過不導致錯誤:
defined('DIR_FS_CATALOG') || define('DIR_FS_CATALOG', 'whatever');
如果您確實需要使用error_reporting()將錯誤報告更改為E_ALL ^ 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);
?>