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

查看所有标签

The Shallows

The Shallows

Nicholas Carr / W. W. Norton & Company / 2011-6-6 / USD 15.95

"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具