首頁 >後端開發 >php教程 >PHP debug_backtrace 函數

PHP debug_backtrace 函數

WBOY
WBOY原創
2016-07-30 13:30:201187瀏覽

PHP debug_backtrace() 函數產生一個 backtrace

此函數傳回一個關聯數組。

<code>下面是可能返回的元素
</code>
字串目前的檔案名稱object物件當前物件type字串目前的呼叫類型,可能的呼叫: : “-For Example one:實例One輸出結果如下:Hi this is a test function Array ( [0] => Array ( [file] => D:wwwMyProjecttestindex4.php
function 字串 目前的函數名稱
字串 - ”回傳nothing - 函數呼叫
args 數組 如果在函數中,列出函數參數。如果在被引用的檔案中,列出被引用的檔案名稱
<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>
[line] => 52

[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>

實例Two輸出結果如下:
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 ) ) ) )


註:在此所有參數都輸出了,分別是:file,line,function,class,object,type,args;




版權聲明:本文為博主原創文章,未經博主允許不得轉載。

以上就介紹了PHP debug_backtrace 函數,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn