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

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

案例1

<?php 
class a{ 
function say($msg) { 
echo "msg:".$msg; 
echo "<pre>";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"); 

案例2

<?php

function one($str1, $str2)
{
    two("Glenn", "Quagmire");
}

function two($str1, $str2)
{
    three("Cleveland", "Brown");
}

function three($str1, $str2)
{
    echo '<pre>';
    debug_backtrace();
}
echo one('a','b');

?>

 

相关文章:

  • 2021-12-04
  • 2021-05-09
  • 2021-12-03
  • 2021-08-11
  • 2022-12-23
  • 2021-12-24
猜你喜欢
  • 2021-09-20
  • 2021-12-30
  • 2021-12-24
  • 2021-11-30
  • 2021-08-28
  • 2021-06-06
  • 2022-01-16
相关资源
相似解决方案