スーパークラスから継承する PHP クラスの絶対パス名を取得しようとしています。シンプルであるべきだと思われます。以下のコードは、可能な限り簡潔に説明していると思います。
// myapp/classes/foo/bar/AbstractFoo.php
class AbstractFoo {
public function getAbsolutePathname() {
// this always returns the pathname of AbstractFoo.php
return __FILE__;
}
}
// myapp/classes/Foo.php
class Foo extends AbstractFoo {
public function test() {
// this returns the pathname of AbstractFoo.php, when what I
// want is the pathname of Foo.php - WITHOUT having to override
// getAbsolutePathname()
return $this->getAbsolutePathname();
}
}
私がオーバーライドしたくない理由getAbsolutePathname()
は、AbstractFoo を拡張する多くのクラスが、ファイルシステムのさまざまな場所にある可能性があり (Foo は実際にはモジュールです)、DRY に違反しているように見えるからです。