How to find out where a function is defined?

How can I find out in which file and line a given function was defined?


You could also do this in PHP itself:

$reflFunc = new ReflectionFunction('function_name');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();

Either use a IDE that allows doing so (I would recomend Eclipse PDT), or you can allways grep it if on Linux, or using wingrep. In Linux it would be something like:

grep -R "function funName" *

from within the root folder of the project.


If you use an IDE like Netbeans, you can CTRL+Click the function use and it will take you to where it is defined, assuming the file is within the project folder you defined.

There's no code or function to do this though.


I assume that by "described" you mean "defined". For this, you ideally need a decent IDE that can do it.


Heres a basic function that will scan your entire project files for a specific string and tell you which file it is in and which char position it starts at using only basic php. Hope this helps someone...

<?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;
}
?>