PHP trigger_error() 函数

PHP 教程 · 2019-01-24 16:28:00

定义和用法

trigger_error() 函数创建用户自定义的错误消息。

trigger_error() 函数用于在用户指定的条件下触发一个错误消息。它可以与内建的错误处理程序一起使用,或者与由 set_error_handler() 函数设置的用户自定义函数一起使用。

当您需要在运行脚本时的某个指定条件下自定义错误消息时,该函数很有用。

如果指定了一个不合法的错误类型,该函数返回 FALSE,否则返回 TRUE。

语法


trigger_error(error_message,error_types)


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

可能的错误类型:

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

实例


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

上面代码的输出如下所示:


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


点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Approximation Algorithms

Approximation Algorithms

Vijay V. Vazirani / Springer / 2001-07-02 / USD 54.95

'This book covers the dominant theoretical approaches to the approximate solution of hard combinatorial optimization and enumeration problems. It contains elegant combinatorial theory, useful and inte......一起来看看 《Approximation Algorithms》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具