php 调试利器debug_print_backtrace()

前端之家收集整理的这篇文章主要介绍了php 调试利器debug_print_backtrace()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如果我们想知道某个方法被谁调用了? debug_print_backtrace可以解决
debug_print_backtrace() 可以打印出一个页面调用过程,从哪儿来到哪儿去一目了然.
不过这是一个PHP5的专有函数,好在pear中已经有了实现,
http://pear.php.net/package/PHP_Compat 测试代码
<div class="codetitle"><a style="CURSOR: pointer" data="12144" class="copybut" id="copybut12144" onclick="doCopy('code12144')"> 代码如下:

<div class="codebody" id="code12144">
<?PHP
class a{
function say($msg) {
echo "msg:".$msg;
echo "
";debug_print_backtrace(); 
}
} class b {
function say($msg) {
$a = new a();
$a->say($msg);
}
} class c {
function construct($msg) {
$b = new b();
$b->say($msg);
}
} $c = new c("test");

输出结果
<div class="codetitle"><a style="CURSOR: pointer" data="3858" class="copybut" id="copybut3858" onclick="doCopy('code3858')"> 代码如下:
<div class="codebody" id="code3858">
msg:test
#0 a->say(test) called at [/var/www/test/test0723.PHP:12]
#1 b->say(test) called at [/var/www/test/test0723.PHP:19]
#2 c->
construct(test) called at [/var/www/test/test0723.PHP:23]

相关链接 http://ch2.php.net/manual/zh/function.debug-print-backtrace.php
http://ch2.php.net/manual/zh/function.debug-backtrace.php

原文链接:https://www.f2er.com/php/27084.html

猜你在找的PHP相关文章