如果我们想知道某个函数被谁调用了呢? debug_print_backtrace方法可以解决!
debug_print_backtrace() 可以打印出一个页面的调用过程,从哪儿来到哪儿去一目了然.
不过这是一个PHP5的专有函数,好在pear中已经有了实现:
http://pear.php.net/package/PHP_Compat

测试代码:

<?php
function one($str1, $str2) { two(“Glenn”, “Quagmire”); }
function two($str1, $str2) { three(“Cleveland”, “Brown”); }
function three($str1, $str2) { debug_print_backtrace(); }
one(“Peter”, “Griffin”);
?>

结果输出:
#0 three(Cleveland, Brown) called at [C:\webfolder\test.php:8]
#1 two(Glenn, Quagmire) called at [C:\webfolder\test.php:4]
#2 one(Peter, Griffin) called at [C:\webfolder\test.php:15]

相关链接

http://ch2.php.net/manual/zh/function.debug-print-backtrace.php
http://ch2.php.net/manual/zh/function.debug-backtrace.php