如何解释 PHPDoc 的 `@property-read` 和 `@property-write` 属性?

发布于 2024-12-14 03:56:34 字数 274 浏览 4 评论 0原文

鉴于 phpDoc 手册,我找不到有关

  • @property-read< 的解释/code>
  • @property-write

但仅限于 @property

他们做什么?

Given the phpDoc manual, I cannot find explanation about that

  • @property-read
  • @property-write

but only of @property.

What do they do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伏妖词 2024-12-21 03:56:34

@property 标签是 phpDocumentor 手册中记录的内容。该标签仅在类文档块中用于记录“神奇”属性/变量,即未在代码中定义的属性/变量,因此不能被“文档块化”。

现在,当您想强调特定的“魔术变量”是只读的(不可写)时,您可以使用@property-read。如果您有一个只写(不可读)的“神奇变量”,您可以使用@property-write。诚然,我很难想象无法读取的只写变量,但由于技术上可以做到这一点,@property-write 可供您记录它。

@property 的这两个“子标签”在您上面链接到的 @property 页面上进行了进一步解释。

The @property tag is what's documented in the phpDocumentor manual. This tag is used only in a class docblock to document a "magic" property/variable, i.e. one that is not defined in the code, and therefore can't be "docblock'd".

Now, when you want to highlight that a particular "magic variable" is read-only (not writable), you'd use @property-read. If you have a "magic variable" that is write-only (not readable), you'd use @property-write. Granted, I have trouble imagining write-only variables that can't be read, but since it's technically possible to do it, @property-write is available for you to document it.

These two "subtags" of @property are explained farther down on the @property page that you linked to above.

逆光下的微笑 2024-12-21 03:56:34

这里有一个关于魔法属性的很好的解释

基本上,@property-write 被解释为 - 顾名思义 - 为只写属性。例如,Eclipse 中的代码完成就利用了这一点。如果您的魔法属性 foo 被声明为“只写”,那么当您键入 $a = $this->f 时,它不会显示在代码完成中。

Here's a good explanation on magic properties.

Basically, @property-write is interpreted - as the name suggests - as a write-only property. The code completion in Eclipse, for example, makes use of this. If your magic property foo is declared "write-only", it wouldn't show up in code completion, when you type $a = $this->f.

双马尾 2024-12-21 03:56:34

@property-read 告诉 IDE(和文档生成器)存在一个神奇的仅用于 Get 的字段。

@property-write 告诉 IDE 存在一个神奇的 Set-only 字段。

PHP 8.1 添加了 readonly 关键字,
它基本上禁止将变量设置为另一个值(初始值除外)。

@property-read tells the IDE (and doc generator) that a magic Get-only field exists.

@property-write tells the IDE that a magic Set-only field exists.

PHP 8.1 added readonly keyword,
which basically forbids setting a variable to another value (except initial value).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文