PHP 中的 user_error() 函数
phpprogrammingserver side programming更新于 2025/9/17 3:52:17
user_error() 函数是 PHP 中 trigger_error() 函数的别名。它用于触发用户错误条件,可以与内置错误处理程序结合使用,也可以与已设置为新错误处理程序的用户定义函数结合使用。
语法
user_error(error_msg, error_type)
参数
error_msg − 指定错误消息。长度限制为 1024 个字符。
error_type −它指定此错误消息的错误类型。
以下是可能的错误类型 −
E_USER_ERROR − 用户生成的致命运行时错误。无法恢复的错误。脚本执行将暂停。
E_USER_WARNING − 用户生成的非致命运行时警告。脚本执行不会暂停。
E_USER_NOTICE − 默认。用户生成的运行时通知。脚本发现了一些可能是错误的东西,但在正常运行脚本时也可能发生。
返回
如果指定的 error_type 错误,则 user_error() 函数返回 FALSE,否则返回 TRUE。
示例
下面是一个例子 −
<?php
if ($demo<10) {
user_error("Number cannot be less than 2");
}
?>
输出
以下是输出 −
PHP Notice: Undefined variable: demo in /home/cg/root/4127336/main.php on line 2 PHP Notice: Number cannot be less than 2 in /home/cg/root/4127336/main.php on line 3

