无法解释的错误信息:Doctrine\ORM version 2.14.1, PHP 8.2, Doctrine\Common\Annotations\AnnotationException

问题描述 投票:0回答:0

我有几个带有注释@ORM\HasLifeCycleCallbacks() 的实体,因为我使用 Doctrine ORM 版本 2.14.1 和 PHP 8.2,我一次又一次地收到以下消息:

[2023 年 3 月 23 日 10:33:22 欧洲/苏黎世] PHP 致命错误:未捕获的 Doctrine\Common\Annotations\AnnotationException:[语义错误] 注释“@Doctrine\ORM\Mapping\prePersist”在方法 Webdreams\Service 中\Entities\Document::setCreatedAt() 从未被导入。您是否忘记为该注释添加“使用”语句?在/home/qowimyky/public_html/apps/wdv-512/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:36

以前PrePersist和PreFlush一直有效,我也没有改代码。

同样奇怪的是,当我在由 new ORM\PrePersist() 和 new ORM\PreFlush() 显式运行的脚本中执行 use Doctrine\ORM\Mapping as ORM 函数时,有一段时间没有显示任何消息。

这是我的实体之一:

命名空间 Webdreams\Service\Entities;

使用 Doctrine\ORM\Mapping 作为 ORM, Webdreams\Extensions\Doctrine\ORM\Util ;

/**

  • @ORM\Entity(repositoryClass="Webdreams\Service\Repositories\DocumentRepository")

  • @ORM\HasLifecycleCallbacks()

  • @ORM\Table(name="documents", options={"charset":"utf8mb4", "collate":"utf8mb4_unicode_ci"}) / 类文档 { /*

    • @ORM\Id
    • @ORM\GeneratedValue(策略="自动")
    • @ORM\列(类型=“整数”) */ 保护 $id = 0;

    /**

    • @ORM\Column(name="updated_at", type="datetime") */ 受保护的 $updatedAt;

    …………

    /**

    • @ORM\prePersist */ 公共函数 setCreatedAt() { $this->updatedAt = new \DateTime('now'); } }

这是 Doctrine\ORM 或 PHP 中的错误吗?有人有什么想法吗? 非常感谢您的帮助。

doctrine-orm annotations fatal-error
© www.soinside.com 2019 - 2024. All rights reserved.