Home >Backend Development >PHP Problem >How to block all errors in php.ini
How to block all errors in php.ini: 1. Open the "php.ini" configuration file and search for the "display_errors" item in it; 2. Set the value of the "display_errors" item to "Off". All PHP error reporting can be turned off, thereby blocking all errors.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Shield all errors in php.ini Method:
Open the php.ini configuration file, search for display_errors in it, and then set the value of display_errors to Off to turn off all PHP error reports. As shown below:
; This directive controls whether or not and where PHP will output errors, ; notices and warnings too. Error output is very useful during development, but ; it could be very dangerous in production environments. Depending on the code ; which is triggering the error, sensitive information could potentially leak ; out of your application such as database usernames and passwords or worse. ; For production environments, we recommend logging errors rather than ; sending them to STDOUT. ; Possible Values: ; Off = Do not display any errors ; stderr = Display errors to STDERR (affects only CGI/CLI binaries!) ; On or stdout = Display errors to STDOUT ; Default Value: On ; Development Value: On ; Production Value: Off ; http://php.net/display-errors display_errors = Off
This method should be the most thorough solution, because it applies to all PHP files.
Extended knowledge: Other ways to mask errors
Use the error control operator: @
PHP supports the use of the error control operator @. Place it before a PHP expression and any error messages the expression may produce will be ignored.
If a custom error handling function is set with set_error_handler(), this error handling function will still be called, and if @ is used before the error statement, the error handling function will return 0.
It should be noted that the @ operator is only valid for expressions. Simply put, if you can get a value from somewhere, you can add the @ operator in front of it. For example, the @ operator can be used before variables, functions, include calls, constants, etc., but it cannot be placed before the definition of a function or class, nor can it be used before conditional structures such as if and foreach statements. The
@ operator is also effective for serious errors that can cause the program to terminate. This means that if @ is used to suppress the error message before a function call that does not exist or has the wrong letter, the program will Die there without any hint.
[Example] Use the @ error control operator to mask errors in the code.
<?php $link = @mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db") or die('数据库连接失败!'); ?>
The running results are as follows:
数据库连接失败!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to block all errors in php.ini. For more information, please follow other related articles on the PHP Chinese website!