【问题标题】:SYMFONY4 : "Notice: Undefined variable: parentClass"SYMFONY4:“注意:未定义的变量:parentClass”
【发布时间】:2019-09-20 18:59:54
【问题描述】:

当我尝试转到调用实体的页面时收到此错误消息。 (例如联系页面,或文章页面)

“注意:未定义的变量:parentClass”将我引向此文件 vendor\doctrine\persistence\lib\Doctrine\Common\Persistence\AbstractManagerRegistry.php 第 176 行

public function getManagerForClass($class)
{
    // Check for namespace alias
    if (strpos($class, ':') !== false) {
        [$namespaceAlias, $simpleClassName] = explode(':', $class, 2);
        $class                              = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
    }
    $proxyClass = new ReflectionClass($class);
    if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
        $parentClass = $proxyClass->getParentClass();
        if (! $parentClass) {
            return null;
        }
    }
        $class = $parentClass->getName();
    foreach ($this->managers as $id) {
        $manager = $this->getService($id);
        if (! $manager->getMetadataFactory()->isTransient($class)) {
            return $manager;
        }
    }
}

我真的不知道该怎么办。 如果有人有想法或已经有这个错误:)

谢谢!

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    您正确缩进的代码如下所示:

    $proxyClass = new ReflectionClass($class);
    if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
        $parentClass = $proxyClass->getParentClass();
        if (! $parentClass) {
            return null;
        }
    }
    $class = $parentClass->getName();
    

    现在,如果$proxyClass->implementsInterface(...) 是FALSE,则没有定义$parentClass,因此会出现错误消息。

    由于代码似乎符合原则,因此可能是一个错误。也许它已修复并且您出于某种原因使用旧版本。也许更新?

    in the current version the line is inside the if-block

    【讨论】:

      【解决方案2】:

      你说得对,我不知道为什么$class = $parentClass->getName(); 不在“如果”之列,问题实际上就是这个!谢谢!

      【讨论】:

        猜你喜欢
        • 2012-09-24
        • 1970-01-01
        • 2021-03-07
        相关资源
        最近更新 更多