This article mainly introduces PHP through the trigger_error to trigger a PHP error example, this article describes the error suppressor @ and through the Trigger_error trigger PHP error example, the need for friends can refer to the
Example of PHP error triggered by Trigger_error in PHP
"Error suppressor @"
In addition to the error_reporting and display_errors settings in PHP.ini, the error_reporting () function, the Ini_set () function, you can also use the error suppressor @ to mask the wrong output.
@ Plus before any expression that will produce an error.
"Trigger PHP error via Trigger_error"
The ability to trigger the error is not limited to the PHP parser, it can also trigger an error through the Trigger_error () function, similar to the exception thrown in the exception, throws an error that can assist in debugging the code.
Cases
The code is as follows:
$num 1 = 1;
$num 2 = ' 2 ';
if (!) ( Is_numeric ($num 1) && is_numeric ($num 2))) {
Error of manually throwing notification level
Trigger_error (' Num1 and num2 must be legal values ', e_user_notice);
}else{
echo $num 1 + $num 2;
}
Echo '
The program continues to execute downward ';
Output:
The code is as follows:
3
Program continues down execution
and
The code is as follows:
$num 1 = 1;
$num 2 = ' 2a ';
if (!) ( Is_numeric ($num 1) && is_numeric ($num 2))) {
Error of manually throwing notification level
Trigger_error (' Num1 and num2 must be legal values ', e_user_notice);
}else{
echo $num 1 + $num 2;
}
Echo '
The program continues to execute downward ';
Output:
The code is as follows:
( ! ) NOTICE:NUM1 and num2 must be valid values in d:practisephperrorerror1.php on line 6
Program continues down execution
"Other" when serious errors such as the database is not connected, you can manually throw the error-replace the PHP built-in e_warning warning with E_user_error.