PHP prints the call function entry address (stack) for convenient adjustment

Source: Internet
Author: User
Today, a BUG occurs on the website and logs are directly written in the database class to see which SQL statement is faulty. The SQL statement is found, but you do not know where the SQL statement comes from, so I thought, if there is a way to check which method is called for the currently running method and which method is called for the previous method, this class

Today, a BUG occurs on the website and logs are directly written in the database class to see which SQL statement is faulty. The SQL statement is found, but you do not know where the SQL statement comes from, so I thought, if there is a way to check which method is called for the currently running method and which method is called for the previous method, this class

Today, a BUG occurs on the website and logs are directly written in the database class to see which SQL statement is faulty. The SQL statement is found, but you do not know where the SQL statement comes from, so I thought, if there is a way to check which method was called for the currently running method, and which method was called for the previous method, and so on, how nice is the portal address. However, I also thought about it before and searched it online, that is, I did not find any relevant method. Today, a colleague (predecessors) said that such debugging in JAVA is widely used, I searched the PHP stack on the Internet for Stack debugging. I found it and wrote my own method.
// Call the stack function to find the source of the function to facilitate debugging.
Function print_stack_trace ()
{
$ Array = debug_backtrace ();
// Print_r ($ array); // complete information
Unset ($ array [0]);
Foreach ($ array as $ row)
{
$ Html. = $ row ['file']. ':'. $ row ['line']. 'line, call method :'. $ row ['function']."

";
}
Return $ html;
}
I call this method in the core query function of my database. The result is as follows:
D: \ wamp \ www \ meilele \ includes \ cls_mysql.php: Row 471. Call method: query

D: \ wamp \ www \ meilele \ includes \ cls_mysql.php: Row 507, call method: getAll

D: \ wamp \ www \ meilele \ receivdes \ lib_common.php: Row 732. Call getAllCached.

D: \ wamp \ www \ meilele \ includes \ init. php: Row 113. Call load_config

D: \ wamp \ www \ meilele \ index. php: 4 rows. Call method: include_once

At a glance, I found the entrance, which is too powerful. There will be another way to debug later

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.