How to set php.ini error reporting: First find and open the php.ini configuration file; then set the content to "error_reporting=E_ALL display_errors=On".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
PHP Turn on error display and set error reporting level
Warning: Never display any error messages in a production environment!
Display errors (display_errors) and error reporting (error_reporting) are two different things. When an error occurs in a PHP script, you can choose whether to report the error (record it in the error log) according to the settings. If display_errors is turned on in the settings, the error message will be printed to the screen at the same time.
Commonly used settings in projects
switch (ENVIRONMENT) { // 对于开发环境,报告所有错误,同时显示到屏幕上 case 'development': error_reporting(-1); ini_set('display_errors', 1); break; // 对于测试和生产环境,不显示错误,5.3 以上的版本,不报告通知、废弃方法、严格这几类错误 case 'testing': case 'production': ini_set('display_errors', 0); if (version_compare(PHP_VERSION, '5.3', '>=')) { error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); } else { error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); } break; default: header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'The application environment is not set correctly.'; exit(1); // EXIT_ERROR }
PHP predefined error constants
The official website defines all error constants, Commonly used ones are:
- E_STRICT (integer) PHP suggestions for code modifications to ensure the best interoperability and forward compatibility of the code.
- E_ALL (integer) All error and warning information except E_STRICT.
- E_ERROR (integer) Fatal runtime error. This type of error is generally an unrecoverable situation, such as a problem caused by memory allocation. The consequence is that the script terminates and does not continue to run.
- E_WARNING (integer) Runtime warning (non-fatal error). Only a prompt message is given, but the script does not terminate.
- E_PARSE (integer) Compile-time syntax parsing error. Parsing errors are generated only by the parser.
- E_NOTICE (integer) Runtime notification. Indicates that the script encounters a situation that may appear as an error, but there may also be similar notifications in scripts that can run normally.
Enable and set the display level in code
ini_set() function
For PHP, you can pass php.ini
file sets various instructions. But sometimes you need to set instructions when the script is running, then you need the ini_set()
function.
string ini_set ( string $varname , string $newvalue )
Set the value of the specified configuration option. This option will retain its new value while the script is running, and will be restored when the script ends.
For example:
ini_set('error_reporting', E_ALL); ini_set('display_errors', 'on');
error_reporting() function
error_reporting()
The function can set the error_reporting directive at runtime. PHP has many error levels. Use this function to set the level when the script is running. If the optional argument is not set, error_reporting() returns the current error reporting level.
The default value for PHP7.2 is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
.
It is recommended to enable E_NOTICE during the development stage to display more possible errors.
<?php // 关闭所有PHP错误报告,相当于 ini_set('error_reporting', 0); error_reporting(0); error_reporting(E_ERROR | E_WARNING | E_PARSE); // 报告 E_NOTICE (报告未初始化的变量或捕获变量名的错误拼写) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // 除了 E_NOTICE,报告其他所有错误 error_reporting(E_ALL ^ E_NOTICE); // 报告所有 PHP 错误 (参见 changelog) error_reporting(E_ALL); // 报告所有 PHP 错误 error_reporting(-1); // 和 error_reporting(E_ALL); 一样 ini_set('error_reporting', E_ALL);
Modify the php.ini configuration file
error_reporting = E_ALL # 报告所有错误 display_errors = On # 显示错误
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of How to set up php.ini error reporting. 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

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
