mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
118 lines
5.2 KiB
HTML
118 lines
5.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>产生一个用户级别的 error/warning/notice 信息</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.trigger-error" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">trigger_error</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.0.1, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">trigger_error</span> — <span class="dc-title">产生一个用户级别的 error/warning/notice 信息</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.trigger-error-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>trigger_error</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$error_msg</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$error_type</code><span class="initializer"> = E_USER_NOTICE</span></span>
|
|
] ) : <span class="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
用于触发一个用户级别的错误条件,它能结合内置的错误处理器所关联,或者可以使用用户定义的函数作为新的错误处理程序(<span class="function"><a href="set_error_handler.html" class="function">set_error_handler()</a></span>)。
|
|
</p>
|
|
<p class="para">
|
|
该函数在你运行出现异常时,需要产生一个特定的响应时非常有用。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.trigger-error-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">error_msg</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
该 error 的特定错误信息,长度限制在了 1024 个字节。超过 1024 字节的字符都会被截断。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">error_type</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
该 error 所特定的错误类型。仅 E_USER 系列常量对其有效,默认是 <strong><code>E_USER_NOTICE</code></strong>。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.trigger-error-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
如果指定了错误的 <code class="parameter">error_type</code> 会返回 <strong><code>FALSE</code></strong> ,正确则返回 <strong><code>TRUE</code></strong>。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.trigger-error-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-466">
|
|
<p><strong>Example #1 <span class="function"><strong>trigger_error()</strong></span> 示例</strong></p>
|
|
<div class="example-contents"><p>
|
|
<span class="function"><a href="set_error_handler.html" class="function">set_error_handler()</a></span> 可见到更多详细的例子。
|
|
</p></div>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$divisor </span><span style="color: #007700">== </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Cannot divide by zero"</span><span style="color: #007700">, </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.trigger-error-notes">
|
|
<h3 class="title">注释</h3>
|
|
<div class="warning"><strong class="warning">Warning</strong>
|
|
<p class="para">
|
|
在 <code class="parameter">error_msg</code> 里的HTML实体 并不会被转义。
|
|
如果错误消息要显示在浏览器里,需要对错误消息使用 <span class="function"><a href="htmlentities.html" class="function">htmlentities()</a></span>。
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.trigger-error-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="error_reporting.html" class="function" rel="rdfs-seeAlso">error_reporting()</a> - 设置应该报告何种 PHP 错误</span></li>
|
|
<li class="member"><span class="function"><a href="set_error_handler.html" class="function" rel="rdfs-seeAlso">set_error_handler()</a> - 设置用户自定义的错误处理函数</span></li>
|
|
<li class="member"><span class="function"><a href="restore_error_handler.html" class="function" rel="rdfs-seeAlso">restore_error_handler()</a> - 还原之前的错误处理函数</span></li>
|
|
<li class="member">The <a href="errorfunc.constants.html" class="link">错误级别常量</a></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |