PHP debug_backtrace() function generates a backtrace
This function returns an associative array.
<code>下面是可能返回的元素 </code>
function | string | current function name |
---|---|---|
line | integer | current line number |
file | String | Current file name |
object | object | current object |
type | string | Current call type, possible calls: Return: "->" - method call returns: "::" - static method call returns nothing - function call |
args | array | If inside a function, lists the function arguments. If in the referenced file, list the referenced file name |
For Example one:
<code><span><span>class</span><span>Hello</span>{</span><span>private</span><span>$var</span>; <span>public</span><span>$var2</span>; <span>protected</span><span>$var3</span>; <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$var</span>,<span>$var2</span>,<span>$var3</span>)</span>{</span><span>$this</span>-><span>var</span>=<span>$var</span>; <span>$this</span>->var2=<span>$var2</span>; <span>$this</span>->var3=<span>$var3</span>; } } <span><span>function</span><span>test</span><span>(Hello <span>$hello</span>)</span>{</span><span>echo</span><span>"Hi this is a test function"</span>.<span>"<br>"</span>; print_r(debug_backtrace()); } <span>$hello2</span>=<span>new</span> Hello(<span>'A'</span>,<span>'B'</span>,<span>'C'</span>); test(<span>$hello2</span>);</code>
The output result of example one is as follows:
Hi this is a test function
Array ( [0] => Array (
[file] => D:wwwMyProjecttestindex4.php
[line] => 52
[function] => test
[args] => Array ( [0] => Hello Object ( [var:Hello:private] => A [var2] => B [var3:protected] => C ) ) ) )
Note: Only four parameters are output here, namely: file, line, function, args;
For Example Two:
<code><span><span>class</span><span>Hello</span>{</span><span>private</span><span>$var</span>; <span>public</span><span>$var2</span>; <span>protected</span><span>$var3</span>; <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$var</span>,<span>$var2</span>,<span>$var3</span>)</span> {</span><span>$this</span>-><span>var</span>=<span>$var</span>; <span>$this</span>->var2=<span>$var2</span>; <span>$this</span>->var3=<span>$var3</span>; } <span><span>function</span><span>test</span><span>(Hello <span>$hello</span>)</span>{</span><span>echo</span><span>"Hi this is a test function"</span>.<span>"<br>"</span>; print_r(debug_backtrace()); } } <span>$hello2</span>=<span>new</span> Hello(<span>'A'</span>,<span>'B'</span>,<span>'C'</span>); <span>$hello2</span>->test(<span>$hello2</span>); </code>
The output result of Example Two is as follows:
Hi this is a test function
Array ( [0] => Array (
[file] => D:wwwMyProjecttestindex4.php
[line] => 54
[function] => test
[class] => Hello
[object] => Hello Object ( [var:Hello:private] => A [var2] => B [var3:protected] => C )
[type] => ->
[args] => Array ( [0] => Hello Object ( [var:Hello:private] => A [var2] => B [var3:protected] => C ) ) ) )
Note: All parameters are output here, namely: file, line, function, class, object, type, args;
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger. .
The above introduces the PHP debug_backtrace function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.