Home > Backend Development > PHP Problem > Take you to understand php error settings

Take you to understand php error settings

PHPz
Release: 2023-04-10 15:00:08
Original
673 people have browsed it

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:

  • E_ERROR: fatal error, the script cannot continue execution;
  • E_WARNING: warning error, the script can continue execution, but there are potential problems;
  • E_NOTICE: Notification error, the script can continue to execute, but there are problems that require the developer's attention;
  • E_STRICT: Strict mode error, usually related to PHP version compatibility;
  • E_DEPRECATED: Outdated Error, indicating that a function or method is no longer recommended, but is still supported for compatibility reasons;
  • E_ALL: includes all error levels, used to set and detect all errors.

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.

  1. Set in php.ini

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
Copy after login

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.

  1. Set in the script

Use the error_reporting function in the script to set the PHP error level. For example:

error_reporting(E_ALL);
Copy after login

At this time, PHP will print out all error messages. Parameters can be modified as needed to set different error levels.

  1. Use the ini_set function

Use the ini_set function to dynamically set the error level of PHP, as shown below:

ini_set('error_reporting', E_ALL);
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template