When developing with PHP, you often need to use the logging function. PHP provides the error_log function, which can save error logs to a local or remote server. The error log is divided into different error levels, including:
- E_ERROR: Serious error, the system cannot continue execution and needs to stop execution immediately.
- E_WARNING: Warning level error, the system can continue to execute.
- E_NOTICE: Notification level error, some values were used before assignment.
- E_STRICT: Tips for coding standards, used to mark some irregularities in code writing.
- E_DEPRECATED: A reminder of obsolete functionality that will be removed in a future version.
- E_PARSE: Syntax analysis error, the code cannot be parsed.
Now, let’s understand these error levels one by one.
- E_ERROR
The E_ERROR error level is the highest level error in PHP and usually causes the PHP program to be unable to continue running. For example, an undefined variable, calling a non-existent method or function, etc. This level of error usually needs to be handled using the trigger_error or set_error_handler function.
The following is a code example that uses the trigger_error function to record error logs:
if(!function_exists('test')){ trigger_error('函数test不存在', E_USER_ERROR); }
- E_WARNING
E_WARNING error level usually means there are some minor problems in the code , will not prevent the PHP program from continuing to run. For example, calling a class or method that does not exist, calling a method that is not accessible, etc. Errors of this level can usually be handled using try...catch statements.
The following is a code example that uses try...catch to capture warning errors:
try{ $test = new Test(); } catch (Error $e) { error_log($e->getMessage()); }
- E_NOTICE
E_NOTICE error level is usually some important The information was not processed correctly. For example, using uninitialized variables, operating on undefined constants, etc. Errors of this level can usually be handled by using the isset function.
The following is a code example that uses the isset function to handle notification errors:
if (!isset($test)) { error_log('未定义的变量'); }
- E_STRICT
The E_STRICT error level is usually used to prompt PHP programmers Write irregular code. For example, using deprecated syntax, inappropriate type hints, etc. Errors of this level can be resolved by modifying the code.
- E_DEPRECATED
The E_DEPRECATED error level is usually used to remind PHP programmers that certain features will be removed in future versions. For example, the parameters of a certain function have changed but the old version of the function parameters are still used. Errors of this level can be resolved by modifying the code.
- E_PARSE
The E_PARSE error level is a syntax analysis error. A syntax error is detected during the correctness check of the PHP program. Usually the program cannot be parsed and executed. For example, forgetting to enter a semicolon at the end of a statement, using invalid keywords, etc. Errors of this level can be resolved by modifying the code.
When writing PHP programs, we should handle various error levels reasonably and record error information in a timely manner to ensure the robustness and stability of the program.
The above is the detailed content of Detailed explanation of error error level in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
