In Symfony2, I saw the code like below:
if (null === $this->rootDir) {
$r = new \ReflectionObject($this);
$this->rootDir = dirname($r->getFileName());
}
why not just use the __DIR__?
if (null === $this->rootDir) {
$this->rootDir = __DIR__;
}
What is difference between them?
__DIR__returns the directory of the file where it is called. The Symphony2 code returns the directory of where the class is defined, which most likely is a different file.