PHP trigger_error()Functions


PHP Error 参考手册Complete PHP Error Reference Manual


Definition and Usage

The trigger_error() function creates a user-defined error message.

The trigger_error() function is used to trigger an error message under user-specified conditions. It can be used together with the built-in error handler, or with a user-defined function set by the set_error_handler() function.

This function is useful when you need to customize an error message under a specified condition while running a script.

If an invalid error type is specified, the function returns FALSE; otherwise, it returns TRUE.

Syntax

trigger_error(error_message,error_types)

Parameters Description
error_message Required. Specifies the error message. Length limited to 1024 characters.
error_types Optional. Specifies the error type of the error message.

Possible error types:

  • E_USER_ERROR - A user-generated fatal runtime error. An unrecoverable error. Stops script execution.
  • E_USER_WARNING - A user-generated non-fatal runtime warning. The script does not stop execution.
  • E_USER_NOTICE - Default. A user-generated runtime notice. The script finds a possible error, but it may also occur during normal script operation.


Examples

<?php
$test=2;
if ($test>1)
{
    trigger_error("A custom error has been triggered");
}
?>

The output of the above code is shown below:

Notice: A custom error has been triggered
in C:webfoldertest.php on line 6


PHP Error 参考手册Complete PHP Error Reference Manual

Other Extensions