Coder Perfect

What’s the best way to figure out where a function is defined?


What is the best way to figure out the file and line a function was defined in?

Asked by foreline

Solution #1

You could also do it directly in PHP:

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

Answered by Tom Haigh

Solution #2

Use an IDE that allows you to do so (I recommend Eclipse PDT), or grep it if you’re on Linux, or use wingrep. It would look like this in Linux:

grep -R "function funName" *

from within the project’s root folder

Answered by Johnco

Solution #3

If you’re using Netbeans, you can CTRL+Click the function name to go to where it’s defined, as long as the file is in the project folder you specified.

However, there is no code or function to accomplish this.

Answered by Stephen Melrose

Solution #4

I believe you mean “defined” when you say “described.” For this, you’ll need a good IDE that can handle it.

Answered by Anton Gogolev

Solution #5

Using only basic php, here’s a simple function that will scan your entire project files for a given text and tell you which file it’s in and what char point it starts at. I hope this is of assistance to someone…


echo findString('./ProjectFolderOrPath/',$find);

function findString($path,$find){
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                        echo $sub.PHP_EOL;
                        $pos = strpos($filesource, $find);
                        if ($pos === false) {
                        } else {
                            echo "The string '$find' was found in the file '$path/$file and exists at position $pos<br />";
    $return = ob_get_contents();
    return $return;

Answered by Lawrence Cherone

Post is based on