Is there any way to know how many times the function was called?

1

I would like to know if in PHP there is some way to find out how many times a given function has been called.

I am speaking natively, since I would also like to do this check for native functions.

Example:

 var_dump($_POST); 

 var_dump($_GET);

 get_function_called_number('var_dump'); // int(2)

To satisfy just the requirements of the question, I'll already demonstrate in the question that I know how to do this for functions I've created.

So:

function call_me()
{
    static $count = 0;
    $count++;

    var_dump($count);
}

call_me(); // imprime int(1)

call_me(); // imprime int(2)

But I would like a solution to know about native functions.

    
asked by anonymous 26.10.2015 / 15:54

1 answer

0

There is a native function called debug_backtrace ()

With the result returned by this function, you can get the information you need.

Otherwise, you would have to create a custom control. Such control is feasible only with the use of OOP.

An example control is to identify calls within an autoloader. However, this does not control native functions. To control them, you would have to create aliases and avoid calling them directly.

    
21.01.2016 / 21:01