0

Possible Duplicate:
How to find out where a function is defined?
get filename of extended class

Working on non OO codes in PHP, I sometimes find myself digging through code to find something as simple as "where that function sits".

function myfunction(){
    where_is_this_function();   
}

My question is, how can i find where is the file where the where_is_this_function() sits

I know there are debuggers, find in files tools and other options, but i would like to know if there is any programmatic way to do so like, because sometimes it's more handy.

get_thefunction_file('where_is_this_function()')
Community
  • 1
  • 1
Jonathan DS
  • 2,050
  • 5
  • 25
  • 48

2 Answers2

1

You can use debug_print_backtrace(); in that function it should pretty-print how it was called and from what file

function myfunction(){
    debug_print_backtrace();//where_is_this_function();   
}

and output a numbered list like

#0  myfunction() called at [/tmp/include.php:10]
#1  include(/tmp/include.php) called at [/tmp/test.php:3]
JKirchartz
  • 17,612
  • 7
  • 60
  • 88
0

If you're just concerned about where the function sits while working in the code and don't need the information runtime, development IDEs such as NetBeans or Eclipse have specific "jump to declaration" functionality.

In NetBeans for example you simply place the cursor somewhere within the "where_is_this_functiob" text and press CTRL+B. NetBeans then tries to load the file and jump directly to the function definition.

I'm pretty sure other editors have some similar functionality.

h00ligan
  • 1,471
  • 9
  • 17