How do I get all the function calls from a php script?

0

Example:

  • index.php

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

Print:

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


Question:

Can anyone get me the getCalledFunctions function?

    
asked by anonymous 02.10.2014 / 18:08

1 answer

1

A reasonable solution demonstrated by Stack Overflow is this response a class named 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 Debug :: log () method whenever you need it in the first line of the body of your functions.

And finally print as desired the Debug :: calls property information.

    
02.10.2014 / 18:48