m3tsys
m3tsys

Reputation: 3969

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

Upvotes: 3

Views: 1063

Answers (3)

Lèse majesté
Lèse majesté

Reputation: 8045

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.

Upvotes: 3

GreenMatt
GreenMatt

Reputation: 18570

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

Upvotes: 3

toomanyairmiles
toomanyairmiles

Reputation: 6485

Adobe Dreamweaver has a site wide/directory text search function as does eclipse workbench, UltraEdit and TopStyle Pro.

Upvotes: 0

Related Questions