简体   繁体   中英

How can i find a function which is included in multiple files from directories and sub directories?

Let's say i have this php function called from multiple php files

do_something($var);

How can i find the files from which the function is called?

later edit: i want to do this on windows

At least some IDE 's have a means of searching through your current project for all instances of certain variables, function calls, etc. If you are using an IDE, check its help.

If you are using a *nix system, you can use grep to search:

grep do_something *.php'

The above will search your current working directory for the text 'do_something' in all files ending with the '.php' extension. You can expand this to search all subdirectories of the current directory using the find command :

find . -name "*.php" -exec grep do_something {} \;

Use 'man grep' and 'man find' from your *nix command line to learn more.

If you are on Windows, I believe the find command can do similar things, I am not as familiar with it, but the basic syntax should look something like:

find "do_something" *.php

Three ways to do this:

  1. Use a sensible directory structure and application design. If you're following OOD and have a clearly laid out directory structure, then it should be very easy to find the declaration for any class and its methods. If the method was declared in a parent class, you just scan up the inheritance tree. If, OTOH, you're writing spaghetti code and using tons of global functions, well... you've got bigger problems.

  2. Consult the documentation. Any sizable application should have a well-documented API, which at minimum should include a list of all classes and their member functions and attributes. The API documentation should also tell you the file that each class is defined in. A quick search in the API would thus turn up the info you need.

  3. Use an intelligent IDE like Eclipse that parses your code and class definitions. Eclipse has an Open Declaration function that will open up the source file where the element was declared and display the declaration.

You should always be doing the first two; the last is just a convenience.

Adobe Dreamweaver具有站点范围/目录文本搜索功能, eclipse workbenchUltraEditTopStyle Pro也是如此

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM