Is there any way to know where the function was called?

0

If I have a huge project and I realize that somewhere in the code, a function is being called, but I do not know which place 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 would like something like:

descubra_onde_a_funcao_foi_chamada('config');

And so something like:

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

How can I do something like this in PHP, just as I demonstrated in the example function?

    
asked by anonymous 26.10.2015 / 16:01

1 answer

3

The debug_print_backtrace() function 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 value of the DEBUG_BACKTRACE_IGNORE_ARGS , which hides the parameters of the called functions.

<?php
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

Example content displayed:

#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]
    
26.10.2015 / 16:09