Definition and usage the Trigger_error () function creates a user-defined error message.
Trigger_error () is used to trigger an error message under a user-specified condition. It is used in conjunction with a built-in error processor, or it can be used with a user-defined function created by the Set_error_handler () function.
If an illegal error type is specified, the function returns FALSE, otherwise returns true.
Grammar Trigger_error (error_message,error_types)
Parameter description error_message required. Specify an error message. Length is limited to 1024 characters. Error_types Optional. The type of error that prescribes the error message. Possible values: E_user_error
e_user_warning
E_user_notice
Copy Code code as follows:
<?php
function Myerror ($errno, $errstr, $errfile, $errline) {
Switch ($errno) {
Case e_user_error:
echo "<b>my error</b>[$errno] $errstr <br/>";
echo "Fatal error in line $errline of file $errfile";
Exit (1);
break;
Case e_user_warning:
echo "<b>my warning</b> [$errno] $errstr";
break;
Default:
echo "Unknown error type:[$errno] $errstr";
break;
}
}
Set_error_handler ("Myerror");
$age =-100;
if ($age <0) {
Trigger_error (' Age with Input must>=0 ', e_user_error);
}
?>