-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.

Community
  • 1
  • 1
Friso Kluitenberg
  • 1,157
  • 1
  • 14
  • 34
  • 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. – Nadh May 05 '12 at 13:51
  • this might help you http://stackoverflow.com/questions/2197851/function-list-of-php-file – Stasik May 05 '12 at 13:57
  • Why don't you now where you put your classes/functions? And why you dont' use _any_ naming convention? – KingCrunch May 05 '12 at 13:59
  • I use naming conventions, but functions and classes are dynamically generated by wordpress including different plugins. So i dont know beforehand – Friso Kluitenberg May 05 '12 at 14:09

1 Answers1

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();
Christian
  • 27,509
  • 17
  • 111
  • 155
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • 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 – Friso Kluitenberg May 05 '12 at 14:09
  • why is a user of 20k+ answering duplicates ? – tereško May 06 '12 at 19:41
  • @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. – KingCrunch May 06 '12 at 20:13
  • 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 May 06 '12 at 20:18
  • @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! :) – KingCrunch May 07 '12 at 08:39