Latest web development tutorials

PHP user_error () function

PHP Error Reference Complete PHP Error Reference

Definition and Usage

user_error () function to create user-defined error message.

user_error () function is used to trigger an error message in the user-specified conditions. It can be used with the built-in error handler, or with the user by the set_error_handler () function is used with the custom setting function.

When you need a custom error message under certain conditions specified when running the script, the function is useful.

If you specify an invalid type of error, the function returns FALSE, otherwise it returns TRUE.

This function is trigger_error () alias function.

grammar

user_error(error_message,error_types)

参数 描述
error_message 必需。规定错误消息。长度限制为 1024 个字符。
error_types 可选。规定错误消息的错误类型。

可能的错误类型:

  • E_USER_ERROR - 用户生成的运行时的致命错误。不能恢复的错误。停止执行脚本。
  • E_USER_WARNING - 用户生成的运行时的非致命警告。脚本没有停止执行。
  • E_USER_NOTICE - 默认。用户生成的运行时的通知。脚本发现可能是一个错误,但也可能在脚本正常运行时发生。


Examples

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

The output of the code above is as follows:

Notice: A custom error has been triggered
inC:webfoldertest.phpon line6


PHP Error Reference Complete PHP Error Reference