-2

Possible Duplicate:
How to find out where a function is defined?

I've searched google for a while and I can't figure it out. I have a known function or class, lets say function/class f_x. This function is defined either in a seperate unkown .php -file.

Is there any way to retrieve the file name of that file? Like you would normally get with FILE? I can't edit those files as I'm writing a plugin for a php system.

I need this to implement a plugin for wordpress which does: - Enumerate all shortcode function - Detect if shortcode is present on page - if not, remove all hooks and filters related to the plugin using the shortcode.

4
  • Hm, do you mean, given a function name, find the PHP file that houses it? If that's the case, you'd have to scan all PHP files and look for an instance, which is impractical and inefficient. Commented May 5, 2012 at 13:51
  • this might help you stackoverflow.com/questions/2197851/function-list-of-php-file Commented May 5, 2012 at 13:57
  • Why don't you now where you put your classes/functions? And why you dont' use any naming convention? Commented May 5, 2012 at 13:59
  • I use naming conventions, but functions and classes are dynamically generated by wordpress including different plugins. So i dont know beforehand Commented May 5, 2012 at 14:09

1 Answer 1

1

Besides the fact, that I don't know, how someone can lose his classes, or functions:

$refFunction = new \ReflectionFunction('myFunction');
echo $refFunction->getFilename();

or

$refClass = new \ReflectionClass('ClassName');
echo $refClass->getFilename();

You can even ask, where it is defined in the file

echo $ref->getStartLine() . ':' . $ref->getEndLine();
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, exactly what I need. I don't loose my classes, but there are other plugins included also. I don't know before hand what files/functions/classes they define
why is a user of 20k+ answering duplicates ?
@tereško The moment I wrote the answer the question wasn't marked as duplicate. However, I don't see a reason the remove the answer now, thus I let others decide, wether "answering a duplicate" is really a reason for downvote.
yes, it wasn't .. but why your name is not the first one in the list of "closers"? As a high-rep user you should have been the want to actually point out the duplicate, instead of rep-whoring.
@tereško You are telling me, that I'm forced to jump around and search duplicates every time I open a question, just because I answered questions in the past and got reputation points for this? Sorry to tell you, but I have a life and I don't get paid for this, thus sometimes I "forget" it ... You should definitely downvote this laziness! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.