Answers:
您也可以在PHP本身中执行此操作:
$reflFunc = new ReflectionFunction('function_name');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
$reflFunc = new ReflectionMethod($this, 'method_name');
如果使用NetBeans之类的IDE,则可以CTRL +单击该函数的使用,并假定文件位于您定义的项目文件夹中,它将带您转到定义的位置。
但是,没有代码或函数可以执行此操作。
我假设“描述”是指“定义”。为此,理想情况下,您需要一个可以做到的体面的IDE。
这是一个基本功能,它将扫描整个项目文件中的特定字符串,并告诉您该文件位于哪个文件中,以及仅使用基本php从哪个字符位置开始。希望这可以帮助某人...
<?php
$find="somefunction()";
echo findString('./ProjectFolderOrPath/',$find);
function findString($path,$find){
$return='';
ob_start();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($path.'/'.$file)){
$sub=findString($path.'/'.$file,$find);
if(isset($sub)){
echo $sub.PHP_EOL;
}
}else{
$ext=substr(strtolower($file),-3);
if($ext=='php'){
$filesource=file_get_contents($path.'/'.$file);
$pos = strpos($filesource, $find);
if ($pos === false) {
continue;
} else {
echo "The string '$find' was found in the file '$path/$file and exists at position $pos<br />";
}
}else{
continue;
}
}
}
}
closedir($handle);
}
$return = ob_get_contents();
ob_end_clean();
return $return;
}
?>
我喜欢Tom的解决方案,所以我想我可以与ReflectionFunction分享更多的技巧(它应该适用于每个PHP 5):
一线打印文件名:
print (new ReflectionFunction("foo"))->getFileName();
请注意,它不会为您显示内部函数的位置(例如_),但仍可以按如下所示打印API。
打印函数的定义和参数:
print new ReflectionFunction("foo");
例:
$ php -r 'print new ReflectionFunction("_");'
Function [ <internal:gettext> function _ ] {
- Parameters [1] {
Parameter #0 [ <required> $msgid ]
}
}
$reflFunc->isInternal() === TRUE
意味着-> getFileName()和-> getStartLine()将返回FALSE。