PHP is an open source, powerful server-side scripting language that is widely used in the field of web development. Generally, when we develop using PHP, we will encounter various errors. These errors can be syntax errors, logic errors, runtime errors, etc. Fully understanding and mastering the relevant knowledge of PHP error settings can help developers better locate and solve problems.
PHP Error Level
In PHP, some error levels are defined to identify the severity of errors in scripts. These error levels include:
Set the error level of PHP
This article mainly introduces how to set the error level of PHP. After understanding the relevant knowledge of error level, we can set PHP in the following ways error level.
You can edit the php.ini file to set the PHP error level. Find the error_reporting parameter in the php.ini file, remove the semicolon (;) and set the error level you need. For example:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
In the above example, E_ALL means that all errors will be displayed, while ~E_DEPRECATED and ~E_STRICT mean that "outdated" and "strict mode" errors will not be displayed.
Use the error_reporting function in the script to set the PHP error level. For example:
error_reporting(E_ALL);
At this time, PHP will print out all error messages. Parameters can be modified as needed to set different error levels.
Use the ini_set function to dynamically set the error level of PHP, as shown below:
ini_set('error_reporting', E_ALL);
The effect is similar to the error_reporting function .
Error logging
In PHP error handling, error logging is a crucial link, which allows us to troubleshoot errors more conveniently. PHP will output error information to the server-side log file by default. Developers can modify the error_log parameter in the php.ini file to specify the location of the log file. For example:
error_log = /var/log/php_error.log
The above settings will log PHP error information to the /var/log/php_error.log file.
Conclusion
This article details how to set the error level of PHP and how to track and troubleshoot errors by recording error logs. Understanding this knowledge can help developers locate and resolve errors more efficiently.
The above is the detailed content of Take you to understand php error settings. For more information, please follow other related articles on the PHP Chinese website!