Possible Duplicate:
How to find out where a function is defined?
I wanna know (programmatically, probably through reflection API) where a certain PHP function is defined.
Possible Duplicate:
How to find out where a function is defined?
I wanna know (programmatically, probably through reflection API) where a certain PHP function is defined.
There's stuff in the ReflectionFunction
class that looks relevant (getFileName
, getStartLine
, etc.).
(Untested)
debug_backtrace()
will give back an array with all calls being made, and also the definition of the functions/methods. The reflection class will give you the definition of the function.
e.g. I use this to log deprectated function within older projects:
function logDeprecated() {
$trail = debug_backtrace();
if ($trail[1]['type']) {
$function = new ReflectionMethod($trail[1]['class'], $trail[1]['function']);
} else {
$function = new ReflectionFunction($trail[1]['function']);
}
$errorMsg = 'Function ' . $trail[1]['function'];
if ($trail[1]['class']) {
$errorMsg .= ' of class ' . $trail[1]['class'];
}
$errorMsg .= ' is deprecated (called from ' . $trail[1]['file'] . '#' . $trail[1]['line'] . ', defined in ' . $function->getFileName() . '#' . $function->getStartLine() . ')';
return $errorMsg;
}
ReflectionMethod::getStartLine()
ReflectionMethod::getFileName()
ReflectionFunction::getStartLine()
ReflectionFunction::getFileName()
probably it is not best solution, but in case you wont find anyting, you can find function location using grep
command if you are using linux.
exec('grep -irn "yourFunctionName" ./library', $response);
foreach ($response as $file) {
list($filename, $line) = explode(":", $file);
}