Finding the PHP File (at run time) where a Class was Defined

Try ReflectionClass

Example:

class Foo {}
$reflector = new \ReflectionClass('Foo');
echo $reflector->getFileName();

This will return false when the filename cannot be found, e.g. on native classes.

Leave a Comment