Trigger_error in PHP: trigger_errorphp. In PHP, trigger_error is used to trigger a PHP error example. in trigger_errorphpPHP, trigger_error is used to trigger a PHP error example. trigger_error used in error_reporting and displ PHP in ini to trigger PHP error example: trigger_errorphp
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:
<? Php
$ 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:
<? Php
$ 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.
Example of triggering PHP errors using trigger_error in PHP [error blocker @] except for error_reporting and displ in php. ini...