无涯教程-PHP错误处理函数 - user_error()

41 阅读1分钟

user_error() - 语法

bool user_error ( string $error_msg [, int $error_type] );

此函数是trigger_error()的别名,用于触发用户错误条件,它可以与内置错误处理程序结合使用,也可以与已设置为新错误处理程序的用户定义函数set_error_handler()一起使用。

error_msg       -  它指定错误消息。长度限制为1024个字符。

error_types     -  它指定此错误消息的错误类型。

                            - E_USER_ERROR        -  用户生成的致命运行时错误,无法恢复的错误,暂停脚本的执行。

                            - E_USER_WARNING  -  非致命用户生成的运行时警告,脚本的执行不会停止。

                            - E_USER_NOTICE      -   默认值,用户生成的运行时通知,脚本发现可能是错误,但在正常运行脚本时也可能发生。

user_error() - 返回值

如果指定了错误的ERROR_TYPE,则此函数返回FALSE,否则返回TRUE。

user_error() - 示例

<?php
    if ($test<10) {
    user_error("Number cannot be less than 10");
}
?> 

这将产生以下输出-

Number cannot be less than 10

参考链接

www.learnfk.com/php/php-fun…