In PHP, the error level determines the severity and handling of the error. Common error levels include: E_WARNING: Warning, which does not necessarily stop script execution. E_NOTICE: Notification, less severe than E_WARNING. E_ERROR: Fatal error that will stop script execution. E_PARSE: Syntax error, will stop the script before it is executed. E_COMPILE_ERROR: The PHP compiler cannot compile the script and will stop the script before it is executed. E_CORE_ERROR: Error in PHP core that will stop the script before it is executed. E_USER_ERROR: A custom error raised by the trigger_error() function that can stop script execution.
In PHP, the error level determines the severity and handling of the error. Understanding what the different error levels mean is critical to properly debugging and handling errors.
The following are some common PHP function error levels:
E_WARNING
E_NOTICE
E_ERROR
E_PARSE
E_COMPILE_ERROR
E_CORE_ERROR
E_USER_ERROR
trigger_error()
function Custom errors can stop script execution. Practical case:
The following code shows how to handle different error levels:
<?php // 记录错误 ini_set('display_errors', 1); ini_set('error_reporting', E_ALL ^ E_NOTICE); // 触发一个警告 echo "警告消息"; // 触发一个错误 if (false) { echo "错误消息"; } ?>
Output:
警告消息 PHP Fatal error: Uncaught Error: Division by zero in ...
In this case, E_WARNING is a non-fatal warning and the script continues execution. E_ERROR, on the other hand, is a fatal error that causes the script to stop executing.
Note:
error_reporting()
function. The above is the detailed content of Error levels for common PHP function errors. For more information, please follow other related articles on the PHP Chinese website!