English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
error_reporting() 函数设置应该报告何种 PHP 错误
int error_reporting ( [int $level] );
error_reporting() 函数能够在运行时设置 error_reporting 指令。PHP 有诸多错误级别,使用该函数可以设置在脚本运行时的级别。如果没有设置可选参数 level,error_reporting() 仅会返回当前的错误报告级别。
序号 | 参数及说明 |
---|---|
1 | level(可选) 它指定当前脚本的错误报告级别。接受数值和常量名称。 |
值 | 常量 | 描述 |
---|---|---|
1 | E_ERROR | 运行时致命的错误。不能修复的错误。停止执行脚本。 |
2 | E_WARNING | 运行时非致命的错误。没有停止执行脚本。 |
4 | E_PARSE | 编译时的解析错误。解析错误应该只由解析器生成。 |
8 | E_NOTICE | 运行时的通知。脚本发现可能是一个错误,但也可能在正常运行脚本时发生。 |
16 | E_CORE_ERROR | PHP 启动时的致命错误。这就如同 PHP 核心的 E_ERROR。 |
32 | E_CORE_WARNING | PHP 启动时的非致命错误。这就如同 PHP 核心的 E_WARNING。 |
64 | E_COMPILE_ERROR | 编译时的致命错误。这就如同由 Zend 脚本引擎生成的 E_ERROR。 |
128 | E_COMPILE_WARNING | 编译时的非致命错误。这就如同由 Zend 脚本引擎生成的 E_WARNING。 |
256 | E_USER_ERROR | Errori fatali generati dall'utente. Questo è come un E_ERROR generato dal programmatore utilizzando la funzione PHP trigger_error(). |
512 | E_USER_WARNING | Errori non fatali generati dall'utente. Questo è come un E_WARNING generato dal programmatore utilizzando la funzione PHP trigger_error(). |
1024 | E_USER_NOTICE | Notifiche generate dall'utente. Questo è come un E_NOTICE generato dal programmatore utilizzando la funzione PHP trigger_error(). |
2048 | E_STRICT | Notifiche di runtime. PHP consiglia di modificare il codice per migliorare l'interoperabilità e la compatibilità del codice. |
4096 | E_RECOVERABLE_ERROR | Errori fatali catturabili. Questo è come un E_ERROR definito dall'utente che può essere catturato da un gestore di errori (vedi set_error_handler()). |
8191 | E_ALL | Tutti i livelli di errori e avvisi, tranne E_STRICT (a partire da PHP 6.0, E_STRICT viene considerato parte di E_ALL). |
Restituisce il livello predefinito di error_reporting, o il livello corrente se non viene fornito un livello.
Di seguito è riportato l'uso di questa funzione error_reporting-
<?php // Chiude tutti i report di errori PHP error_reporting(0); // Rende noto errori di esecuzione semplici error_reporting(E_ERROR | E_WARNING | E_PARSE); // Rende noto E_NOTICE anche bene (rende noto le variabili non inizializzate) // O cattura errori di battitura del nome delle variabili error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // A parte E_NOTICE, rende noto tutti gli altri errori error_reporting(E_ALL ^ E_NOTICE); // Rende noto tutti gli errori PHP (vedi changelog) error_reporting(E_ALL); // Rende noto tutti gli errori PHP error_reporting(-1); // E_ALL e error_reporting(E_ALL) sono uguali ini_set('error_reporting', E_ALL); ?>