PhpDoc 在 class 中包含的文件中为自己添加符号

PhpDoc adding notation for self in a file included inside a class

我有一个 class,其中包含一个文件,方法如下:

class.php 文件中:

class A {

const CONST1 = 5;

/** @var int $a */
var $a = 5;

public function call()
{
    include( 'b.php' );
}

public function do_some_magic()
{
    // magic stuff...
}

public static function static_func()
{
    // some code...
}

}

文件b.php:

<?php
/** @var A $this */
/** @var A self */ // This doesn't work

$this->do_some_magic();

echo '['.$this->a.']';

self::static_func();

echo '['.self::CONST1.']';

我将 PhpStorm 用作 IDE,在 b.php 文件中,如果我想转到 do_some_magic() 的定义或 a 变量的定义,它将正确地转到相应的class.php 文件中的方法或变量定义,但如果我想转到常量 CONST1 的定义或静态方法的定义 static_func(),它说 "Cannot find definition to go to",所以我认为 /** @var A self */不是包含文件中的有效符号。

我的问题是:在 PhpDoc 中有什么方法可以告诉 IDE 包含文件中的 self 是什么类型?

我搜索了一个答案,但目前看来只有这样才能在包含的文件中自动完成,您将不得不使用 class 名称进行静态调用。当然,如果您将文件包含在不同的 classes 中并且您希望 self 表示包含文件的特定 class,这将失败。

所以 b.php 看起来像:

<?php
/** @var A $this */
/** @var A self */ // This doesn't work

$this->do_some_magic();

echo '['.$this->a.']';

A::static_func();

echo '['.A::CONST1.']';

如果您找到更好的答案,请告诉我。

此致,

安迪