<!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>Generates a backtrace</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.debug-print-backtrace.html">debug_print_backtrace</a></div> <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.debug-backtrace" class="refentry"> <div class="refnamediv"> <h1 class="refname">debug_backtrace</h1> <p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">debug_backtrace</span> — <span class="dc-title">Generates a backtrace</span></p> </div> <div class="refsect1 description" id="refsect1-function.debug-backtrace-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <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> ]] )</div> <p class="para rdfs-comment"> <span class="function"><strong>debug_backtrace()</strong></span> generates a PHP backtrace. </p> </div> <div class="refsect1 parameters" id="refsect1-function.debug-backtrace-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">options</code></em></span> <dd> <p class="para"> As of 5.3.6, this parameter is a bitmask for the following options: <table class="doctable table"> <caption><strong> <span class="function"><strong>debug_backtrace()</strong></span> options</strong></caption> <tbody class="tbody"> <tr> <td>DEBUG_BACKTRACE_PROVIDE_OBJECT</td> <td> Whether or not to populate the "object" index. </td> </tr> <tr> <td>DEBUG_BACKTRACE_IGNORE_ARGS</td> <td> Whether or not to omit the "args" index, and thus all the function/method arguments, to save memory. </td> </tr> </tbody> </table> Before 5.3.6, the only values recognized are <strong><code>TRUE</code></strong> or <strong><code>FALSE</code></strong>, which are the same as setting or not setting the <strong><code>DEBUG_BACKTRACE_PROVIDE_OBJECT</code></strong> option respectively. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">limit</code></em></span> <dd> <p class="para"> As of 5.4.0, this parameter can be used to limit the number of stack frames returned. By default (<em><code class="parameter">limit</code></em>=<em>0</em>) it returns all stack frames. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.debug-backtrace-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an array of associative <span class="type"><a href="language.types.array.html" class="type array">array</a></span>s. The possible returned elements are as follows: </p> <p class="para"> <table class="doctable table"> <caption><strong>Possible returned elements from <span class="function"><strong>debug_backtrace()</strong></span></strong></caption> <thead> <tr> <th>Name</th> <th>Type</th> <th>Description</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> The current function name. See also <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> The current line number. See also <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> The current file name. See also <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> The current <a href="language.oop5.html" class="link">class</a> name. See also <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> The current <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> The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned. </td> </tr> <tr> <td>args</td> <td><span class="type"><a href="language.types.array.html" class="type array">array</a></span></td> <td> If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s). </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 changelog" id="refsect1-function.debug-backtrace-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.4.0</td> <td> Added the optional parameter <em><code class="parameter">limit</code></em>. </td> </tr> <tr> <td>5.3.6</td> <td> The parameter <em><code class="parameter">provide_object</code></em> changed to <em><code class="parameter">options</code></em> and additional option <strong><code>DEBUG_BACKTRACE_IGNORE_ARGS</code></strong> is added. </td> </tr> <tr> <td>5.2.5</td> <td> Added the optional parameter <em><code class="parameter">provide_object</code></em>. </td> </tr> <tr> <td>5.1.1</td> <td> Added the current <span class="type"><a href="language.types.object.html" class="type object">object</a></span> as a possible return element. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.debug-backtrace-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-449"> <p><strong>Example #1 <span class="function"><strong>debug_backtrace()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// filename: /tmp/a.php<br /><br /></span><span style="color: #007700">function </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 /> echo </span><span style="color: #DD0000">"\nHi: </span><span style="color: #0000BB">$str</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br /> </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">?><br /></span><br /><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// filename: /tmp/b.php<br /></span><span style="color: #007700">include_once </span><span style="color: #DD0000">'/tmp/a.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p> Results similar to the following when executing <var class="filename">/tmp/b.php</var>: </p></div> <div class="example-contents screen"> <div class="cdata"><pre> Hi: friend array(2) { [0]=> array(4) { ["file"] => string(10) "/tmp/a.php" ["line"] => int(10) ["function"] => string(6) "a_test" ["args"]=> array(1) { [0] => &string(6) "friend" } } [1]=> array(4) { ["file"] => string(10) "/tmp/b.php" ["line"] => int(2) ["args"] => array(1) { [0] => string(10) "/tmp/a.php" } ["function"] => string(12) "include_once" } } </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.debug-backtrace-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.trigger-error.html" class="function" rel="rdfs-seeAlso">trigger_error()</a> - Generates a user-level error/warning/notice message</span></li> <li class="member"> <span class="function"><a href="function.debug-print-backtrace.html" class="function" rel="rdfs-seeAlso">debug_print_backtrace()</a> - Prints a backtrace</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.debug-print-backtrace.html">debug_print_backtrace</a></div> <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>