7

In PHP, get_included_files() returns an array with the names of included files.

In a similar fashion, is there any way to get an array with the names of called functions with parameters?

7 Answers 7

9

In this way, Is any way to get an array with the names of called functions with parameters?

No.

What you can do is a debug_backtrace() which will show all the function calls (with parameters) that lead to the execution of the line you are doing the backtrace from (the "call stack"), but that's different from all functions that were ever called in the script.

What do you want to do? Maybe there's a different approach.

Sign up to request clarification or add additional context in comments.

1 Comment

@Ozzone for workaround solutions you would have to be more verbose - what is the nature of the problem, how getting a list of all functions would help, etc. Maybe what you need is an actual debugger?
6

I was searching for something similar and found xdebug's tracing very useful.

Here's an example of how it could look like: http://devzone.zend.com/1135/tracing-php-applications-with-xdebug/

Comments

5

I was trying to achieve what you want and finally came up with an reasonable solution.

Make a class named Debug and include that above every file you want to debug in. Build yourself a function that prints nicely the information stored in $calls.

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);
    }
}

Call this function everytime you declare a function first line in the functionbody: Debug::log($message(optional) )

Comments

2

Not that I'm aware.

You can however use debug_backtrace to get the currently active function/method hierarchy.

Comments

1

I don't think there's a way to do what you want. Sorry.

The closest I can get is the function_exists() function, which will tell you whether a specific function has been loaded.

What exactly do you want to achieve here? I can't see a use case (outside of a php_info() type screen) that would require a list of available functions.

Comments

1

You will have to install it as an extension, but a profiler like XHProf will give you a breakdown of which functions are called and how long they take, as well as a callgraph.

Comments

1

XHProf or Webgrind/KCachegrind will show you the functions called, but not their parameters.

You could also use get_defined_functions, which gives you a list of all functions defined. But it won't show you which functions have actually been called, and with what parameters.

If you really need to know the parameters, I don't know of any tools other than a custom logger like the one Henze provided in his answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.