Get php class file path from class name – ReflectionClass

During development of common library for WordPress plugins and themes ( WordPress development helper library ), I just want to find from which plugin it is called ( I just want to debug the code, but I used in many plugins and i am not able to track from which plugin it is actually loading ).

Then  I found about ReflectionClass,  reports information about a class.

You can read more detail about ReflectionClass from php.net.

Here is how to get file path from class name

$autoloader_reflector = new ReflectionClass("RT_WP_Autoload");
$class_file_nanme = $autoloader_reflector->getFileName();
echo dirname($class_file_nanme);

This is same as reflection api in java, There are some good reflection examples to get you started reflection api in java at http://docs.oracle.com/javase/tutorial/reflect/index.html

Advertisements

One thought on “Get php class file path from class name – ReflectionClass

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s