How to get the path of a derived class from an inherited method?
Yes. Building on Palantir's answer:
class Parent {
protected function getDir() {
$rc = new ReflectionClass(get_class($this));
return dirname($rc->getFileName());
}
}
Using ReflectionClass::getFileName
with this will get you the dirname the class Child
is defined on.
$reflector = new ReflectionClass("Child");
$fn = $reflector->getFileName();
return dirname($fn);
You can get the class name of an object with get_class()
:)