AsTeR
AsTeR

Reputation: 7521

How to trace PHP files callstack used to render a page?

For many "on the rush" web development (CMS customisation or simple helping hand to a friend beggin "please help, I can't remove this div on my wordpress page") one common problem appears : what is the code behind the page where our problem lives.

Then my question is simple : is there any tool / method that can ease the searching of the scripts implied in a given page production on a php based webapp ?

Something that can build a call tree for a given page would be great !

Upvotes: 2

Views: 378

Answers (2)

Paul
Paul

Reputation: 6871

xdebug provides a navigable callstack and much much more. On their documentation page there are a long list of wonderful things.

Upvotes: 2

helloandre
helloandre

Reputation: 10721

you're looking for debug_backtrace()

This is a particularly helpful function taken from the CakePHP framework:

function debug($var = false, $showHtml = false, $showFrom = true) {
            if ($showFrom) {
                $calledFrom = debug_backtrace();
                echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
                echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
            }
            echo "\n<pre class=\"debug\">\n";

            $var = print_r($var, true);
            if ($showHtml) {
                $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
            }
            echo $var . "\n</pre>\n";
    }

Upvotes: 2

Related Questions