Find out where the function comes from?

From time to time, I get bloated, undocumented, erroneous PHP code to fix. I have several tools that I use to fix such code as quickly as possible.

One thing that I don’t know how to do, occasionally makes me sad to look for where the function is located (in which file it is defined). Please note: I do not want to know where the function is called from.

For example, I would like to be able to do this:

//file1.php
function foo(){
    echo 'bar';
}

.

//file2.php
where_is_function('foo');//error
include('file1.php');
echo where_is_function('foo');//outputs'file1.php'
+3
source share
3 answers

IDE, ​​ netbeans eclipse. , , ( ).

netbeans. ctrl-click , netbeans , , .

+11

grep grep- . ack, . , -. , , Eclipse .

grep, cd , grep , , . :

cd project/
grep -Rn "def wallace(" .

Ack :

cd project/
ack "def wallace("
+4

Try the following:

function getFunctionLocation($fname) {  
    $includeFilesString = implode(" ", get_included_files());  
    return system("grep 'function $fname' $includeFilesString -l");          
}

But if it's just for development purposes, what they should be, then just run

grep -r "function functionName" *

from the base directory

+2
source

Source: https://habr.com/ru/post/1751314/


All Articles