Get a list of called functions in PHP

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

Similarly, is there a way to get an array with the names of the called functions with parameters?

+7
php
source share
7 answers

I tried to achieve what I wanted and finally came up with a reasonable solution.

Create a class called Debug and include it above each file that you want to debug. Create a function that prints 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 every time you declare the first function of a function in a function: Debug::log($message(optional) )

+4
source share

Thus, is there a way to get an array with the names of the called functions with parameters?

Not.

What you can do is debug_backtrace() , which will show all function calls (with parameters) that lead to the execution of the line you make backtrace from ("call stack"), but this is different from all the functions that have ever been called in the script.

What do you want to do? Perhaps there is a different approach.

+9
source share

I was looking for something similar and found that the xdebug trace is very useful.

Here is an example of how it might look: http://devzone.zend.com/1135/tracing-php-applications-with-xdebug/

+5
source share

Not that I knew.

However, you can use debug_backtrace to get the current active hierarchy of functions / methods.

+2
source share

I don’t think there is a way to do what you want. Unfortunately.

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

What exactly do you want to achieve here? I do not see an example of use (outside the screen like php_info ()), which requires a list of available functions.

+1
source share

You will need to install it as an extension, but a profiler, such as XHProf , will give you a breakdown of what functions are called and how long they take, as well as the call.

+1
source share

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

You can also use get_defined_functions , which gives you a list of all the functions defined. But it will not show you which functions were actually called, and with what parameters.

If you really need to know the parameters, I don’t know any tools other than a specialized registrar, like the one that was proposed by Henze in his answer.

+1
source share

All Articles