Home  >  Article  >  php教程  >  php 调试利器debug_print_backtrace()

php 调试利器debug_print_backtrace()

WBOY
WBOYOriginal
2016-06-06 20:41:171358browse

debug_print_backtrace() 是一个很低调的函数,很少有人注意过它.不过当我对着一个对象调用另一个对象再调用其它的对象和文件中的一个函数出错时,它正在一边笑呢

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


测试代码
复制代码 代码如下:
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");

输出结果
复制代码 代码如下:
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]

相关链接


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn