跳转到PHP中的函数声明


Jumping to function declarations in PHP

我有一个类似的类

class bank
{
    public $accounts;
    public function __construct()
    {
           $accounts = new Accounts();
    }
    public function fun1()
    {
           ///some code
    }
}

fun1()中,当使用时,我无法获得自动完成(在PHPStorm和Eclipse中)功能

$this->accounts->..any function

但直接使用时效果良好

$accounts->..auto complete works fine here

我们能在第一种情况下实现同样的目的吗?

更新:感谢Berry Langerak正确地指出了这一点。

另外,有可能吗

class bank
{
    public $accounts;
    public function __construct()
    {
           $this->accounts = new Accounts();
    }
    public function fun1()
    {
           ///Note changing the reference now
           $this->accounts = new OldAccounts();
           $this->accounts->..it still shows the functions of Accounts Class, can we override this setting in PHPStorm
    }
}

我们可以重写行为并显示新类的函数吗?引用指向

这是因为在构造函数中将"new Accounts"设置为局部变量,而不是将其设置为类变量(无$this);

class bank
{
    public $accounts;
    public function __construct()
    {
           $this->accounts = new Accounts();
    }
    public function fun1()
    {
           $this->accounts->doStuff( );
           /* @var OldAccounts $this->accounts */
           $this->accounts = new OldAccounts;
    }
}

这是因为该变量尚未文档化。这将使IDE了解参考(第3行):

/* @var Accounts */
$accounts

我认为这是因为您没有将其定义为类变量。IE应为protected $accountspublic $accountsprivate $accounts