debug_backtrace() 函數生成回溯。它返回一個關聯數組。可能的返回元素如下 -
名稱 | 類型 | 描述 |
---|---|---|
function | string | 當前函數名稱。 |
line | integer | 當前行號。 |
file | string | 當前文件名。 |
class | string | 當前類名。 |
object | string | 當前對象。 |
type | string | 當前調用類型。如果是方法調用,則返回 "->"。如果是靜態方法調用,則返回 "::"。如果函數調用,則不返回任何內容。 |
arg | array | 如果在函數內部,則列出函數參數。如果在包含的文件中,則列出包含的文件名。 |
用法
debug_backtrace(options, limit)
參數
options- 以下給定選項的位掩碼 -
- DEBUG_BACKTRACE_PROVIDE_OBJECT:是否填充"object"索引
- DEBUG_BACKTRACE_IGNORE_ARGS:是否省略"args"索引,以及所有函數/方法參數,以節省內存。
limit- 限製打印的堆棧幀數
返回
debug_backtrace() 函數返回一個關聯數組。上麵提到了可能的返回元素。
示例
以下是一個例子 -
<?php
function display($str) {
echo "Hi:$str";
var_dump(debug_backtrace());
}
display('hello');
?>
輸出
以下是輸出 -
Hi:helloarray(1) { [0]=> array(4) { ["file"]=> string(36) "/var/www/tutorialspoint/php/test.php" ["line"]=> int(8) ["function"]=> string(8) "printStr" ["args"]=> array(1) { [0]=> &string(6) "hello" } } }
相關用法
- PHP debug_print_backtrace()用法及代碼示例
- PHP debug_zval_dump()用法及代碼示例
- PHP decbin()用法及代碼示例
- PHP decoct()用法及代碼示例
- PHP dechex()用法及代碼示例
- PHP deg2rad()用法及代碼示例
- PHP decoct( )用法及代碼示例
- PHP define()用法及代碼示例
- PHP decbin( )用法及代碼示例
- PHP defined()用法及代碼示例
- PHP dechex( )用法及代碼示例
- PHP disk_total_space()用法及代碼示例
- PHP disk_total_space( )用法及代碼示例
- PHP dir()用法及代碼示例
- PHP date_default_timezone_set()用法及代碼示例
- PHP date_create_immutable()用法及代碼示例
- PHP date_get_last_errors()用法及代碼示例
- PHP date_parse()用法及代碼示例
注:本文由純淨天空篩選整理自Samual Sam大神的英文原創作品 debug_backtrace() function in PHP。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。