Simple example of PHP stack debugging operation

  • 2021-10-16 01:10:59
  • OfStack

This article illustrates the PHP stack debugging operation. Share it for your reference, as follows:

Do you want to know the current function is called by which files, if we know these paths, we can very well understand the process of the execution of the program, this is very important, but also to understand the basis of other programs, so here I will introduce you to a stack debugging method in php, in fact, it is a built-in php function debug_backtrace() ;

The following is a little introduction under it, the specific or to see the manual oh, like to see the manual programmers are promising


$statcks = debug_backtrace();
$tmp_arr = array();
if(!$stacks) return $tmp_arr;
foreach($stacks as $k=>$v)
{
  $tmp[$k]['file'] = isset($v['file']) ? $v['file'] : '--';
  $tmp[$k]['line'] = isset($v['line'])? $v['line'] : '--';
  $tmp[$k]['function'] = isset($v['function']) ? $v['function'] : '--';
}

Run results:

Array
(
[0] = > Array
(
[file] = > D:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
[line] = > 128
[function] = > get_total_rows
)
[1] = > Array
(
[file] = > --
[line] = > --
[function] = > index
)
[2] = > Array
(
[file] = > D:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
[line] = > 46
[function] = > call_user_func
)
[3] = > Array
(
[file] = > --
[line] = > --
[function] = > get_nav
)
[4] = > Array
(
[file] = > D:\wwwroot\CodeIgniter\system\core\CodeIgniter.php
[line] = > 360
[function] = > call_user_func_array
)
[5] = > Array
(
[file] = > D:\wwwroot\CodeIgniter\index.php
[line] = > 205
[function] = > require_once
)
)

Here is the printed array, which is very good

For more readers interested in PHP, please check the topic of this site: "PHP Error and Exception Handling Method Summary", "php String (string) Usage Summary", "PHP Array (Array) Operation Skills Complete Book", "PHP Operation and Operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Syntax Introduction Course", "php Object-Oriented Programming Introduction Course", "php+mysql Database Operation Introduction Course" and "php Common Database Operation Skills Summary"

I hope this article is helpful to everyone's PHP programming.


Related articles: