How to get all function calls from a php script?

Asked

Viewed 94 times

0

Example:

  • index php.

    <?php
    foo();
    bar();
    
    print_r(getCalledFunctions(__FILE__));
    

Print:

array
    0 => 'foo'
    1 => 'bar'


Question:

Can someone return me the getCalledFunctions function?

  • Is that a question? I don’t understand...

  • Yes, I want the getCalledFunctions function...

  • Ah... I don’t think there’s any way to do that. At least that reminds me.

  • He’s got it in the Stackoverflow community in English, I just don’t know if it’s what he’s looking for. http://stackoverflow.com/questions/3881588/get-a-called-functions-list-in-php

1 answer

1

A demonstrated reasonable solution in this answer Stack Overflow creates a class called Debug and include it above any file you want to debug.

class Debug {
    private static $calls;

    public static function log($message = null)
    {
        if(!is_array(self::$calls))
            self::$calls = array();

        $call = debug_backtrace(false);
        $call = (isset($call[1]))?$call[1]:$call[0];

        $call['message'] = $message;
        array_push(self::$calls, $call);
    }
}

Invoke the method Debug::log() whenever you need in the first line of the body of your functions.

And finally print as you wish the property information Debug::calls.

  • Putz... I’ll have to put in all the functions???

Browser other questions tagged

You are not signed in. Login or sign up in order to post.