PHP user_error()Function


PHP Error 参考手册Complete PHP Error Reference Manual

Definition and Usage

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

The user_error() function is used to trigger an error message under user-specified conditions. It can be used 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 certain specified conditions while running a script.

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

This function is trigger_error()an alias of the function.

Syntax

user_error(error_message,error_types)

Parameter Description
error_message Required. Specifies the error message. The length limit is 1024 characters.
error_types Optional. Specifies the error type of the error message.

Possible error types:

  • E_USER_ERROR - A fatal runtime error generated by the user. An unrecoverable error. Stops script execution.
  • E_USER_WARNING - A non-fatal runtime warning generated by the user. The script does not stop executing.
  • E_USER_NOTICE - Default. A runtime notice generated by the user. The script has detected something that may be an error, but it may also occur during normal script execution.


Examples

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

The output of the above code is as follows:

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


PHP Error 参考手册Complete PHP Error Reference Manual Other Extensions