php bug 調試助手 debug_print_backtrace()


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');

?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM