PHP: Find the file where a class was defined

It's annoying when you are looking for a particular class in a system you are not very familiar with, you end up looking all over the system file by file hoping to find the class so you can make changes to the code as you require.

Well there is a simple solution which will allow you find the file where the class is defined, using the reflector class we can pinpoint the exact path to the script file that defines a given class.

All you need to do is place this in the code near where you are calling the class:

$reflector = new ReflectionClass('CLASSNAME');
echo $reflector->getFileName();

Just replace CLASSNAME with the name of the class you wish to track down.

Facebooktwitterredditpinterestlinkedinmail
Author: Dean WilliamsI'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags:
,
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments