Home > Backend Development > PHP Tutorial > Stack debugging in php

Stack debugging in php

WBOY
Release: 2016-08-08 09:19:50
Original
1056 people have browsed it

Do you want to know which files are called by the current function? If we know these paths, we can well understand the execution process of the program. This is very important and is also the basis for understanding other people's programs. So here I will give you Let’s introduce a stack debugging method in php. It is actually a function built into phpdebug_backtrace();

The following is a brief introduction. You still need to read the manual for details. Programmers who like to read manuals are The promising

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


Array
(
    [<span>0</span>]<span> =></span> Array
        (
            [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
            [line]<span> =></span><span>128</span>
            [<span>function</span>]<span> =></span> get_total_rows
        )

    [<span>1</span>]<span> =></span> Array
        (
            [file]<span> =></span> --
            [line]<span> =></span> --
            [<span>function</span>]<span> =></span> index
        )

    [<span>2</span>]<span> =></span> Array
        (
            [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
            [line]<span> =></span><span>46</span>
            [<span>function</span>]<span> =></span> call_user_func
        )

    [<span>3</span>]<span> =></span> Array
        (
            [file]<span> =></span> --
            [line]<span> =></span> --
            [<span>function</span>]<span> =></span> get_nav
        )

    [<span>4</span>]<span> =></span> Array
        (
            [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\system\core\CodeIgniter.php
            [line]<span> =></span><span>360</span>
            [<span>function</span>]<span> =></span> call_user_func_array
        )

    [<span>5</span>]<span> =></span> Array
        (
            [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\index.php
            [line]<span> =></span><span>205</span>
            [<span>function</span>]<span> =></span> require_once
        )

)</code>
Copy after login

Here is the printed array, very good

Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces stack debugging in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template