You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PhpDocs的@param标签描述中链接其他方法/类/属性?

可以在PhpDocs的@param标签描述中内联链接项目内元素吗?

当然可以,你示例中使用的{@link}标签是PhpDoc标准支持的内联链接语法,完全可以在@param标签的描述文本中(包括@return、@throws等所有文档描述区域)内联链接项目中的方法、类、属性、常量等元素。

常用链接语法示例

  • 链接当前类的方法:{@link myOtherMethod()}
  • 链接跨类的方法:{@link \App\Services\MyClass::myOtherMethod()}
  • 链接类:{@link \App\Services\MyClass}
  • 链接类属性:{@link \App\Services\MyClass::$myProperty}
  • 自定义链接显示文本:{@link \App\Services\MyClass::myMethod() 获取数据的方法}

实际代码示例

/**
 * My method's description.
 *
 * @param string $myArg Pass here result of {@link myOtherMethod()}.
 *
 * @return bool
 */
public function myMethod($myArg) {
    // TODO: code here.
}

只要你的项目代码结构规范,主流的文档生成工具(如phpDocumentor、Doxygen)都能正确解析这类链接,并在生成的文档中创建可跳转的关联链接。

内容的提问来源于stack exchange,提问作者Top-Master

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 07:20:41