【问题标题】:PHP 7.1 Doctrine proxy issue with nullable types可空类型的 PHP 7.1 Doctrine 代理问题
【发布时间】:2017-09-28 10:07:09
【问题描述】:

我正在使用 php7.1 的新功能,它允许在项目 Symfony 3 上返回可为空的类型,但是在实体中使用它时遇到问题:

<?php
// ....
public function getCreatedBy(): ?string
{
    return $this->createdBy;
}

当我使用这个功能时,我遇到了这个错误:

Type error: Return value of 
Proxies\\__CG__\\NS\\ModulesBundle\\Entity\\Account::getCreatedBy() 
must be of the type string, null returned

我查看了使用 Symfony 自动创建的类的代码,发现:

<?php
// ...
public function getCreatedBy(): string
{

    $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCreatedBy', []);

    return parent::getCreatedBy();
}

如您所见,该类型不可为空。

有人可以帮助我吗?谢谢

【问题讨论】:

  • 你清除缓存了吗?
  • 是的,我清除了缓存
  • 这是与 Doctrine 相关的问题,与 Symfony 本身无关。
  • 是的,我通过将 lib 教义/doctrine-common 升级到 2.8 版解决了这个问题

标签: php doctrine php-7.1


【解决方案1】:

我通过从 2.6 版升级到 2.8 版的学说/学说通用库来解决了这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    相关资源
    最近更新 更多