PHP debug_backtrace() 函數產生一個 backtrace
此函數傳回一個關聯數組。
<code>下面是可能返回的元素 </code>
function | 字串 | 目前的函數名稱 |
---|---|---|
字串 | 目前的檔案名稱 | |
物件 | 當前物件 | |
字串 | 目前的呼叫類型,可能的呼叫: : “- | 字串 - ”回傳nothing - 函數呼叫 |
args | 數組 | 如果在函數中,列出函數參數。如果在被引用的檔案中,列出被引用的檔案名稱 |
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> | 實例One輸出結果如下:Hi this is a test function |
[function] => test
[args] => Array ( [0] => Hello Object ( [var:Hello:private] => A [var2] => B [var3:protected] => C ) ) ) )註:在此只輸出四個參數,分別是: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>
Hi this is a test function[line] => 54Array ( [0] => Array (
[file] => D:wwwMyProjecttestindex4.php
[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 ) ) ) )
註:在此所有參數都輸出了,分別是:file,line,function,class,object,type,args;
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
以上就介紹了PHP debug_backtrace 函數,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。