Finding the PHP File (at run time) where a Class was Defined
For ReflectionClass in a namespaced file, add a prefix "\" to make it global as following:
$reflector = new \ReflectionClass('FOO');
Or else, it will generate an error said ReflectionClass in a namespace not defined. I didn't have rights to make comment for above answer, so I write this as a supplement answer.
Try ReflectionClass
- ReflectionClass::getFileName — Gets a filename
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.