Anas Salman
Anas Salman

Reputation: 372

List all functions used by php call

Is there a way to list all functions used by php call?

For example let's assume that I have a page called example.com/page_to_test.php and this page uses multiple functions within the page itself or from other classes.

What I want is a list of all functions used during the call (at runtime).

Upvotes: 0

Views: 1504

Answers (2)

Philipp
Philipp

Reputation: 15639

You could register a tick function to achieve this

declare(ticks = 1);
$calls = array();
function tracer() {
    global $calls;
    $bt = debug_backtrace();
    if (count($bt) <= 1) return;
    $function = $bt[1];
    $call = $function['function'];
    if (isset($function['class'])) {
        $call = $function['class'] . '::' . $call;
    }
    $calls[$call] = true;
}
register_tick_function('tracer');

After execution of your script, $calls contains each called function in it's keys.

But just do this for debug purpose, as it's very slow.

Upvotes: 1

Shakti Phartiyal
Shakti Phartiyal

Reputation: 6254

What can help you is the PHP function

debug_backtrace()

Read more about it at: http://php.net/manual/en/function.debug-backtrace.php

Upvotes: 0

Related Questions