相关疑难解决方法(0)

为什么我在引入属性类型提示时突然收到“在初始化之前不能访问类型化属性”错误?

我已经更新了我的类定义以使用新引入的属性类型提示,如下所示:

class Foo {

    private int $id;
    private ?string $val;
    private DateTimeInterface $createdAt;
    private ?DateTimeInterface $updatedAt;

    public function __construct(int $id) {
        $this->id = $id;
    }


    public function getId(): int { return $this->id; }
    public function getVal(): ?string { return $this->val; }
    public function getCreatedAt(): ?DateTimeInterface { return $this->createdAt; }
    public function getUpdatedAt(): ?DateTimeInterface { return $this->updatedAt; }

    public function setVal(?string $val) { $this->val = $val; }
    public function setCreatedAt(DateTimeInterface $date) { $this->createdAt = $date; }
    public function setUpdatedAt(DateTimeInterface $date) { …
Run Code Online (Sandbox Code Playgroud)

php type-hinting doctrine-orm php-7 php-7.4

62
推荐指数
2
解决办法
5万
查看次数

标签 统计

doctrine-orm ×1

php ×1

php-7 ×1

php-7.4 ×1

type-hinting ×1