PHP 7.1 Doctrine 代理问题与可空类型

标签 php doctrine php-7.1

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

<?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();
}

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

有人可以帮助我吗?谢谢

最佳答案

我通过将doctrine/doctrine-common库从2.6版本升级到2.8版本解决了这个问题

关于PHP 7.1 Doctrine 代理问题与可空类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46466464/

相关文章:

php - Doctrine 2 注释,添加自定义 sql - 空间索引

php - 使用 Doctrine 按 FIELD() 排序,这可能吗?

php - 如何在 Ubuntu 中为 PHP 7.1 安装 bcmath

php - WordPress URL 更改失败

javascript - 特维利奥 : 3rd caller can barge in to a call in progress

Symfony2 使用 QueryBuilder 批量删除

mysql - 如何在 Symfony 3 中使用 Doctrine 在类型 "json_array"的列上添加复合索引?

PHP 可遍历类型提示

窗口提交方法内的Javascript停止工作

php - 在 Magento 的前端显示产品创建和最后编辑日期