Home >Backend Development >PHP Tutorial >PHP debugging tool debug_print_backtrace()_PHP tutorial

PHP debugging tool debug_print_backtrace()_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:031073browse

If we want to know who called a certain method? debug_print_backtrace can solve it
debug_print_backtrace() can print out the calling process of a page, and it is clear where it comes from.
But this is a proprietary function of PHP5 , Fortunately, there is already an implementation in pear,
http://pear.php.net/package/PHP_Compat

Test code

Copy code The code is as follows:

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

Output results
Copy code The code is as follows:

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]

Related links

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325806.htmlTechArticleIf we want to know who called a certain method? debug_print_backtrace can solve the problem. debug_print_backtrace() can print out a page. The calling process, where it comes from and where it goes...
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