uTools-Manuals/docs/php/debug_backtrace.html
2019-04-08 23:22:26 +08:00

286 lines
10 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>产生一条回溯跟踪(backtrace)</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.debug-backtrace" class="refentry">
<div class="refnamediv">
<h1 class="refname">debug_backtrace</h1>
<p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">debug_backtrace</span> &mdash; <span class="dc-title">产生一条回溯跟踪(backtrace)</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.debug-backtrace-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>debug_backtrace</strong></span>
([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = DEBUG_BACKTRACE_PROVIDE_OBJECT</span></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$limit</code><span class="initializer"> = 0</span></span>
]] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>debug_backtrace()</strong></span> 产生一条 PHP 的回溯跟踪(backtrace)。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.debug-backtrace-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">options</code></dt>
<dd>
<p class="para">
截至 5.3.6,这个参数是以下选项的位掩码:
<table class="doctable table">
<caption><strong><span class="function"><strong>debug_backtrace()</strong></span> 选项</strong></caption>
<tbody class="tbody">
<tr>
<td>DEBUG_BACKTRACE_PROVIDE_OBJECT</td>
<td>
是否填充 &quot;object&quot; 的索引。
</td>
</tr>
<tr>
<td>DEBUG_BACKTRACE_IGNORE_ARGS</td>
<td>
是否忽略 &quot;args&quot; 的索引,包括所有的 function/method 的参数,能够节省内存开销。
</td>
</tr>
</tbody>
</table>
在 5.3.6 之前,仅仅能使用的值是 <strong><code>TRUE</code></strong> 或者 <strong><code>FALSE</code></strong>,分别等于是否设置 <strong><code>DEBUG_BACKTRACE_PROVIDE_OBJECT</code></strong> 选项。
</p>
</dd>
<dt>
<code class="parameter">limit</code></dt>
<dd>
<p class="para">
截至 5.4.0,这个参数能够用于限制返回堆栈帧的数量。
默认为 (<code class="parameter">limit</code>=<em>0</em>) ,返回所有的堆栈帧。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.debug-backtrace-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
返回一个包含众多关联数组的 <span class="type"><a href="language.types.array.html" class="type array">array</a></span>
以为为有可能返回的元素:
</p>
<p class="para">
<table class="doctable table">
<caption><strong>有可能从 <span class="function"><strong>debug_backtrace()</strong></span> 返回的元素</strong></caption>
<thead>
<tr>
<th>名字</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>function</td>
<td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td>
<td>
当前的函数名,参见:
<a href="language.constants.predefined.html" class="link">__FUNCTION__</a>
</td>
</tr>
<tr>
<td>line</td>
<td><span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span></td>
<td>
当前的行号。参见:
<a href="language.constants.predefined.html" class="link">__LINE__</a>
</td>
</tr>
<tr>
<td>file</td>
<td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td>
<td>
当前的文件名。参见:
<a href="language.constants.predefined.html" class="link">__FILE__</a>
</td>
</tr>
<tr>
<td>class</td>
<td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td>
<td>
当前 <a href="language.oop5.html" class="link">class</a> 的名称。参见
<a href="language.constants.predefined.html" class="link">__CLASS__</a>
</td>
</tr>
<tr>
<td>object</td>
<td><span class="type"><a href="language.types.object.html" class="type object">object</a></span></td>
<td>
当前的 <a href="language.oop5.html" class="link">object</a>
</td>
</tr>
<tr>
<td>type</td>
<td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td>
<td>
当前调用的类型。如果是一个方法,会返回 &quot;-&gt;&quot;。如果是一个静态方法,会返回 &quot;::&quot;
如果是一个函数调用,则返回空。
</td>
</tr>
<tr>
<td>args</td>
<td><span class="type"><a href="language.types.array.html" class="type array">array</a></span></td>
<td>
如果在一个函数里,这会列出函数的参数。
如果是在一个被包含的文件里,会列出包含的文件名。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.debug-backtrace-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.4.0</td>
<td>
添加了可选的参数 <code class="parameter">limit</code>
</td>
</tr>
<tr>
<td>5.3.6</td>
<td>
参数 <code class="parameter">provide_object</code> 改成 <code class="parameter">options</code>,并且增加了可选参数
<strong><code>DEBUG_BACKTRACE_IGNORE_ARGS</code></strong>
</td>
</tr>
<tr>
<td>5.2.5</td>
<td>
添加了可选参数 <code class="parameter">provide_object</code>
</td>
</tr>
<tr>
<td>5.1.1</td>
<td>
添加了当前的 <span class="type"><a href="language.types.object.html" class="type object">object</a></span> 为可能返回的元素。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.debug-backtrace-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-456">
<p><strong>Example #1 <span class="function"><strong>debug_backtrace()</strong></span> 范例</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;filename:&nbsp;/tmp/a.php<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">a_test</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nHi:&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">debug_backtrace</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">a_test</span><span style="color: #007700">(</span><span style="color: #DD0000">'friend'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;<br /></span><br /><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;filename:&nbsp;/tmp/b.php<br /></span><span style="color: #007700">include_once&nbsp;</span><span style="color: #DD0000">'/tmp/a.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>
执行 <var class="filename">/tmp/b.php</var> 返回的结果类似于以下:
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Hi: friend
array(2) {
[0]=&gt;
array(4) {
[&quot;file&quot;] =&gt; string(10) &quot;/tmp/a.php&quot;
[&quot;line&quot;] =&gt; int(10)
[&quot;function&quot;] =&gt; string(6) &quot;a_test&quot;
[&quot;args&quot;]=&gt;
array(1) {
[0] =&gt; &amp;string(6) &quot;friend&quot;
}
}
[1]=&gt;
array(4) {
[&quot;file&quot;] =&gt; string(10) &quot;/tmp/b.php&quot;
[&quot;line&quot;] =&gt; int(2)
[&quot;args&quot;] =&gt;
array(1) {
[0] =&gt; string(10) &quot;/tmp/a.php&quot;
}
[&quot;function&quot;] =&gt; string(12) &quot;include_once&quot;
}
}
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.debug-backtrace-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="trigger_error.html" class="function" rel="rdfs-seeAlso">trigger_error()</a> - 产生一个用户级别的 error/warning/notice 信息</span></li>
<li class="member"><span class="function"><a href="debug_print_backtrace.html" class="function" rel="rdfs-seeAlso">debug_print_backtrace()</a> - 打印一条回溯。</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>