How to tell what module is running from a function call? I wrote a piece of shared code, and I am trying to figure out which module is actually calling the specific function. I am looking to have a mode to turn on debug inside of the shared module if it is being called from a particular module. Also this is in Drupal 7.

To call the shared module, I am using the following to call the function, made generic:

module_load_include('inc','rest_api','rest_api');
_rest_api_do_request();
You could get the calling function from calling debug_backtrace(). Another way would be to pass it in:

_rest_api_do_request(__FUNCTION__);


However, either seems like a bad pattern. It's fine for debugging, but a function shouldn't require knowledge of what it is calling it. That's an unnecessary dependency.