Questions tagged «type-hinting»

类型提示将函数参数绑定到特定对象或对其进行强类型化。

2
为什么在引入属性类型提示时突然出现“初始化前不能访问类型化属性”错误?
我已经更新了类定义,以利用新引入的属性类型提示,如下所示: 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 …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.