gpt4 book ai didi

php - __DIR__ VS 使用反射

转载 作者:可可西里 更新时间:2023-11-01 00:26:09 25 4
gpt4 key购买 nike

在 Symfony2 中,我看到如下代码:

    if (null === $this->rootDir) {
$r = new \ReflectionObject($this);
$this->rootDir = dirname($r->getFileName());
}

为什么不直接使用 __DIR__

    if (null === $this->rootDir) {
$this->rootDir = __DIR__;
}

它们有什么区别?

最佳答案

__DIR__ 返回调用它的文件的目录。 Symphony2 代码返回定义类的目录,这很可能是一个不同的文件。

关于php - __DIR__ VS 使用反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6275429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com