PHP Print Call Function entry address (stack) for easy mode

Source: Internet
Author: User
Tags php print

Http://blog.sina.com.cn/s/blog_4f9fc6e10100rhn5.html

Today the site appears a bug, and then directly in the database class to write the log, see which SQL is out of the question, the SQL statement is found, but do not know where this SQL statement from, so I think, if there is a way to see the current running method is called by which method, And how the previous method called, and so on, to find the entry address. But I have also thought about it before, and also searched the Internet, that is, did not find the relevant method, today a colleague (predecessors) said Java inside this debugging used is very common, called this kind of stack debugging, I was on the web search PHP stack. I found it, and then write my own way out.
Call the stack function to find the source of the calling function to facilitate debugging
function Print_stack_trace ()
{
$array =debug_backtrace ();
Print_r ($array);//information is complete
unset ($array [0]);
foreach ($array as $row)
{
$html. = $row [' file ']. $row [' line ']. ' Line, calling method: '. $row [' function ']. " <p> ";
}
return$html;
}
I call this method in the core query function of my database and print the results as follows:
d:\wamp\www\meilele\includes\cls_mysql.php:471 line, calling method: Query

d:\wamp\www\meilele\includes\cls_mysql.php:507 line, calling method: GetAll

d:\wamp\www\meilele\includes\lib_common.php:732 line, calling method: Getallcached

D:\wamp\www\meilele\includes\init.php:113 line, calling method: Load_config

D:\wamp\www\meilele\index.php:4 line, calling method: Include_once

At a glance, has been found the entrance, too strong. There's one more way to debug later.


Or use the following method:

$e = new Exception;
Var_dump ($e->gettraceasstring ());





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.