我可以在 PHPDoc 中的 @method 行上使用 @see 吗?

Can I use a @see on a @method row in PHPDoc?

当使用 PHPs __call 使 class 扩展 2 classes 时, 您可以使用 @method 让 IDE 知道这些方法存在。

但是当要求 IDE 跳转到方法的声明时,您最终会在 @method-row 上,一种不被卡住的方法是添加一个 @see 行高于或低于。但是添加该行和一个分隔行,使 PHPDoc 成为 long/high.

的 3 倍

是否可以在同一行添加 @see

看到了一些按原样使用它的示例,以及一些在内部使用它的示例 {}。 在我的 IDE (PhpStorm) 中对其进行了测试,跳转至 @see 的声明仅在其位于单独的行时才有效。

PHPDoc 是否允许我们在与 @method 相同的行上使用 @see?如果是这样,正确的语法是什么?

示例:

<?php
class a { function ma() { return "a"; } }
class b { function mb() { return "b"; } }

/**
 * Class c
 *
 * @method string mb() { @see b::mb() }
 */
class c extends a
{
    /** @var b b */
    public $b;

    function __construct() { $this->b = new b(); }
    function mc() { return "c"; }

    function __call($name, $arguments)
    {
        return call_user_func_array([$this->b, $name], $arguments);
    }
}

$c = new c();
var_dump($c->mb());

PHPDoc 还没有正式的标准。 PHPDocumentor 是事实上的标准,但 PHP FIG 也在开发一个标准。

来自the PHPStorm docs

In PHPDoc comments, PhpStorm supports formatting options in compliance with ZEND, PEAR, and other standards.

正如你我都发现的那样,要弄清楚 PHPStorm 究竟支持什么需要反复试验。

PHPDocumentor 确实支持 @see 内联:

Structural Elements, or inline text in a long description, tagged with the @see tag will show a link in their description.

PHP 图的 proposed standard 状态:

Specific Tags MAY have an "Inline PHPDoc" section at the end of the "Tag" definition... An example is the @method tag. This tag can be augmented using an "Inline PHPDoc" to provide additional information regarding the parameters, return value or any other tag supported by functions and methods.

奇怪的是 @method 定义没有明确说明这一点。

我认为这一切意味着您可以在 PHPDoc 注释中的 @method 行上使用 @see,但不要指望 PHPStorm 能够识别它。您的语法是正确的,根据 "standards" 它应该保留在 @method 的末尾。