PHP debug_backtrace() 函數(shù)
定義和用法
PHP debug_backtrace() 函數(shù)生成一個(gè) backtrace。
該函數(shù)返回一個(gè)關(guān)聯(lián)數(shù)組。下面是可能返回的元素:
名稱 | 類型 | 描述 |
---|---|---|
function | 字符串 | 當(dāng)前的函數(shù)名。 |
line | 整數(shù) | 當(dāng)前的行號。 |
file | 字符串 | 當(dāng)前的文件名。 |
class | 字符串 | 當(dāng)前的類名 |
object | 對象 | 當(dāng)前對象。 |
type | 字符串 | 當(dāng)前的調(diào)用類型,可能的調(diào)用:
|
args | 數(shù)組 | 如果在函數(shù)中,列出函數(shù)參數(shù)。如果在被引用的文件中,列出被引用的文件名。 |
語法
debug_backtrace()
例子
<?php function one($str1, $str2) { two("Glenn", "Quagmire"); } function two($str1, $str2) { three("Cleveland", "Brown"); } function three($str1, $str2) { print_r(debug_backtrace()); } one("Peter", "Griffin"); ?>
輸出:
Array ( [0] => Array ( [file] => C:\webfolder\test.php [line] => 7 [function] => three [args] => Array ( [0] => Cleveland [1] => Brown ) ) [1] => Array ( [file] => C:\webfolder\test.php [line] => 3 [function] => two [args] => Array ( [0] => Glenn [1] => Quagmire ) ) [2] => Array ( [file] => C:\webfolder\test.php [line] => 14 [function] => one [args] => Array ( [0] => Peter [1] => Griffin ) ) )