Example of a PHP error triggered by trigger_error in PHP
This article describes how to trigger a PHP Error Using trigger_error in PHP. This article describes the error blocker @ and trigger a PHP Error Using trigger_error. For more information, see
Example of a PHP error triggered by trigger_error in PHP
[Error blocker @]
In addition to setting error_reporting and display_errors, error_reporting (), and ini_set () functions in php. ini, you can also use the error blocker @ to Block Error output.
@ Before any expression that produces an error.
[Trigger_error triggers PHP errors]
The function of triggering an error is not limited to the PHP parser, but can also be used to trigger an error through the trigger_error () function. Similar to an exception thrown in an exception, an error is thrown to help debug the code.
[Example]
The Code is as follows:
$ Num1 = 1;
$ Num2 = '2 ';
If (! (Is_numeric ($ num1) & is_numeric ($ num2 ))){
// Manually throw a notification-Level Error
Trigger_error ('num1 and num2 must be valid number', E_USER_NOTICE );
} Else {
Echo $ num1 + $ num2;
}
Echo'
Program continues to run down ';
Output:
The Code is as follows:
3
Program continues to run down
And:
The Code is as follows:
$ Num1 = 1;
$ Num2 = '2a ';
If (! (Is_numeric ($ num1) & is_numeric ($ num2 ))){
// Manually throw a notification-Level Error
Trigger_error ('num1 and num2 must be valid number', E_USER_NOTICE );
} Else {
Echo $ num1 + $ num2;
}
Echo'
Program continues to run down ';
Output:
The Code is as follows:
(! ) Notice: num1 and num2 must be valid values in D: \ practice \ php \ Error \ error1.php on line 6
Program continues to run down
[Others] When the database cannot be connected and other serious errors, You can manually throw an error -- replace PHP's built-in E_WARNING warning with E_USER_ERROR.