PHP8,如何在属性中写评论?

发布于 2025-01-20 15:41:29 字数 662 浏览 0 评论 0原文

我正在从注释迁移到属性,但我有疑问。 我应该如何为我的方法编写注释以解释它们的功能?

我应该像这样结合注释和属性吗?

/**
 * This route does this and that.
 */
#[Route('/my/route/', name:'my_route')]
public function myRoute(): Response

但它很丑。或者相反,甚至更难看:

#[Route('/my/route/', name:'my_route')]
/**
 * This route does this and that.
 */
public function myRoute(): Response

或者我应该给它们加上标签?但它没有被 IDE 正确解析(当我将鼠标悬停在该方法上时,我没有看到该描述)

# This method does this and that
#[Route('/my/route/', name:'my_route')]
public function myRoute(): Response

我知道这个问题听起来像是一个基于选项的问题,但我正在寻找是否有“官方”推荐的方法,我不能没有找到任何关于此的内容,所有有关属性的示例都没有任何评论......

I am migrating from annotations to attributes, but I have a doubt.
How should I write comments to my methods, to explain their functionality?

Should I combine annotations and attributes, like this?

/**
 * This route does this and that.
 */
#[Route('/my/route/', name:'my_route')]
public function myRoute(): Response

But it's ugly. Or opposite, even uglier:

#[Route('/my/route/', name:'my_route')]
/**
 * This route does this and that.
 */
public function myRoute(): Response

Or should I put them with an hashtag? But it's not parsed correctly by IDEs (I don't see that description when I mouseover the method)

# This method does this and that
#[Route('/my/route/', name:'my_route')]
public function myRoute(): Response

I know this question sounds like an option-based one, but I'm looking if there is an "official" recommended way, I couldn't find anything about this, all the examples about attributes don't have any comment...

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文