debug_backtrace
產生一條回溯跟踪(backtrace)
debug_backtrace()
函數生成backtrace(回溯跟踪)。
該函數顯示由debug_backtrace()
函數代碼生成的數據。
返回一個關聯數組。可能返回的元素如下:
名稱 | 類型 | 描述 |
---|---|---|
function | string | 當前函數名稱 |
line | integer | 當前行號 |
file | string | 當前文件名 |
class | string | 當前類名 |
object | object | 當前對象 |
type | string |
當前調用類型。可能的調用:
|
args | array | 如果在函數中,列出函數參數。如果在被引用的文件中,列出被引用的文件名。 |
生成PHP backtrace:
<?php function a ( $txt ) { b ( "Glenn" ) ; } function b ( $txt ) { c ( "Cleveland" ) ; } function c ( $txt ) { var_dump ( debug_backtrace ( ) ) ; } a ( "Peter" ) ; ?>
以上代碼的輸出類似這樣:
Array ( [0] => Array ( [file] => C:\webfolder\test.php [line] => 6 [function] => c [args] => Array ( [0] => Cleveland ) ) [1] => Array ( [file] => C:\webfolder\test.php [line] => 3 [function] => b [args] => Array ( [0] => Glenn ) ) [2] => Array ( [file] => C:\webfolder\test.php [line] => 11 [function] => a [args] => Array ( [0] => Peter ) ) )
debug_backtrace ( options , limit ) ;
參數 | 描述 |
---|---|
options |
可選。規定以下選項的位掩碼:
|
limit | 可選。限制返回堆棧幀的數量。默認為( limit =0) ,返回所有的堆棧幀。 |