Define and use the trigger_error() function to create user-defined error messages. trigger_error() is used to trigger an error message under a user-specified condition. It works with the built-in fault handler 1 and can also be used with user-defined functions created by the set_error_handler() function.
If an illegal error type is specified, the function returns false, otherwise true. Grammar trigger_error (error_message error_types) The parameter description error_message is required. Specify error messages. The length limit is 1024 characters. error_types optional. Specifies the error type of the error message. Possible values: • E_USER_ERROR •E_USER_WARNING •E_USER_NOTICE
<?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 you input must>=0',E_USER_ERROR);
}
?>