PHP debug_backtrace() 函數產生一個 backtrace
該函數返回一個關聯陣列。
下面是可能返回的元素
| function |
字串 |
當前的函數名 |
| line |
整數 |
當前的行號 |
| file |
字串 |
當前的檔案名稱 |
| object |
對象 |
當前對象 |
| type |
字串 |
當前的調用類型,可能的調用: 返回: “->” - 方法調用返回: “::” - 靜態方法調用返回 nothing - 函數調用 |
| args |
數組 |
如果在函數中,列出函數參數。如果在被引用的檔案中,列出被引用的檔案名稱 |
For Example one:
classHello{private$var; public$var2; protected$var3; publicfunction__construct($var,$var2,$var3){$this->var=$var; $this->var2=$var2; $this->var3=$var3; } }functiontest(Hello $hello){echo"Hi this is a test function"."
"; print_r(debug_backtrace());}$hello2=new Hello('A','B','C');test($hello2);
執行個體One輸出結果如下:
Hi this is a test function
Array ( [0] => Array (
[file] => D:\www\MyProjecttest\index4.php
[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:
classHello{private$var; public$var2; protected$var3; publicfunction__construct($var,$var2,$var3) {$this->var=$var; $this->var2=$var2; $this->var3=$var3; } functiontest(Hello $hello){echo"Hi this is a test function"."
"; print_r(debug_backtrace()); }}$hello2=new Hello('A','B','C');$hello2->test($hello2);
執行個體Two輸出結果如下:
Hi this is a test function
Array ( [0] => Array (
[file] => D:\www\MyProjecttest\index4.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教程有興趣的朋友有所協助。