Is there any reflection/introspection/magic in PHP that will let you find the PHP file where a particular class (or function) was defined?
In other words, I have the
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
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.
if you had an includes folder, you could run a shell script command to "grep" for "class $className" by doing: $filename = ``grep -r "class $className" $includesFolder/*\
and it would return which file it was in. Other than that, i don't think there is any magic function for PHP to do it for ya.