我可以用 phpstorm 指示方法 php 返回的类型吗?
Can I indicate type returned by method php with phpstorm?
我使用 __call() 魔术 php 方法根据我自己的指令调用不存在的方法。
我想知道如何向 phpstorm 指示:这个不存在的方法返回了一个 class 的实例?
示例:
class Baz
{
function __call()
{
return new Bar();
}
function test()
{
$this->foo()->bar();
}
}
class Bar
{
function bar()
{
//do something
}
}
我要为所有当前 class Baz 申报:
/** @return foo() Bar */
我希望 PhpSotrm 找到 bar() 方法源和 concider foo() 就像一个 Bar 实例对象。
我该怎么做?
你可以使用魔术方法注释
/**
* @method Bar foo()
*/
class Baz
{
...
我使用 __call() 魔术 php 方法根据我自己的指令调用不存在的方法。
我想知道如何向 phpstorm 指示:这个不存在的方法返回了一个 class 的实例?
示例:
class Baz
{
function __call()
{
return new Bar();
}
function test()
{
$this->foo()->bar();
}
}
class Bar
{
function bar()
{
//do something
}
}
我要为所有当前 class Baz 申报:
/** @return foo() Bar */
我希望 PhpSotrm 找到 bar() 方法源和 concider foo() 就像一个 Bar 实例对象。
我该怎么做?
你可以使用魔术方法注释
/**
* @method Bar foo()
*/
class Baz
{
...