在给定的PHP代码中,child_func()函数调用parent_func()函数,该函数进一步调用grandparent_func()函数,从而生成调用堆栈。
推荐学习:《PHP教程》
PHP打印调用堆栈的三种方法如下:
方法1:使用debug_print_backtrace()函数打印调用堆栈。
例:<?php
// 用于打印PHP调用堆栈的PHP程序
//调用函数parent_func
function child_func() {
parent_func();
}
// 调用grandparent_func函数
function parent_func() {
grandparent_func();
}
// 函数的作用是:打印调用堆栈
function grandparent_func() {
debug_print_backtrace();
}
//主函数调用
child_func();
?>
输出:#0 grandparent_func() called at [/home/905a3b4d90f10b30521fedcb56c99fba.php:12]
#1 parent_func() called at [/