Is there any way of knowing where the function was called?

Asked

Viewed 688 times

0

If I have a huge project and I realize that somewhere in the code, a function is being called, but I don’t know where it is, is there any way to find out?

Example:

#index.php

// nada aqui nesse script

#config.php

$config['database'] = config('database');

#view.php

$base_url = config('base_name');

I’d like something like:

descubra_onde_a_funcao_foi_chamada('config');

And so return something like:

    array(
      0 => array( 'file' => 'config.php', 'line' => 10),
      1 => array('file'  => 'view.php', 'line' => 15)
   );

You can do something like this, in PHP, in the same way I demonstrated in the example function?

  • http://answall.com/questions/94628/existe-alguma-forma-de-saber-quantas-vezes-a-fun%C3%A7%C3%A3o-called possible duplicate @Wallace ?

  • 1

    Location where the function was called is different from how many times it was called. Help me out, here!

  • got it, would you find it too broad to gather this question in the other ? a function that checks where it was called and counts how many times it was executed ?

  • Yes, they are different subjects. Unless the function does both, without complicating the midfield.

  • @Gabrielrodrigues, I usually group questions, but sometimes it is impossible (I don’t like giant answers)

1 answer

3

The function debug_print_backtrace() displays the call stack to the point where the function is executed.

Although the documentation does not show, this function receives an optional parameter with the constant value DEBUG_BACKTRACE_IGNORE_ARGS, which hides the parameters of the called functions.

<?php
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

Example of displayed content:

#0  c() called at [/tmp/include.php:10]
#1  b() called at [/tmp/include.php:6]
#2  a() called at [/tmp/include.php:17]
#3  include(/tmp/include.php) called at [/tmp/test.php:3]
  • There is no function where I pass the function name as parameter and return only its call locations?

  • Apparently, we have a little problem: This function works when called inside a function, it is not?

  • 1

    @Wallacemaxters some Ides have tools that make this process. For example, Netbeans has a tool called "find uses" that does just that

  • Look, this is nice. I’ll take a look. Apparently, to do it by PHP is kind of complex

Browser other questions tagged

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