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
Copy Code code as follows:
<?php
$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 ' <br/> Program continues down-execution ';
Output:
Copy Code code as follows:
3
Program continues down execution
and
Copy Code code as follows:
<?php
$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 ' <br/> Program continues down-execution ';
Output:
Copy Code code as follows:
( ! ) NOTICE:NUM1 and num2 must be valid values in D:\practise\php\Error\error1.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.