在PHPDocumentor中键入强制转换

时间:2013-11-19 15:23:09

标签: php phpstorm phpdoc

PHPStorm中的PHPDocumentor是否有任何类型转换? 我的PHPStorm智能感知很顽固,我需要教他如何表现。

这是我的情况:

我有一个管理器,它实例化所有扩展相同类的类。 通常我会在它返回后投出我的类,但PHP不知道如何做到这一点。 IntelliSense和PHPDocumentor支持对我来说已足够,但我不知道如何输入强制转换。

这是代码:

class Plugin 
{

}

class HelloPlugin extends Plugin
{
    public function hello()
    {

    }
}

class PluginManager 
{
    /** @var HelloPlugin */
    public $helloPlugin;

    function __construct()
    {
        $this->helloPlugin = $this->getPlugin('HelloPlugin');

        // Here my PHPStorm IntelliSense doesn't provide 'hello()' function for 'helloPlugin' because return type overwrote original type
        // I get error: method 'hello' not found in class
        $this->helloPlugin->hello();
    }

    /**
     * @param string $pluginClass
     * @return Plugin
     */
    function getPlugin($pluginClass)
    {
        return new $pluginClass;
    }

}

1 个答案:

答案 0 :(得分:2)

我认为它实际上不可能:(,除非你以某种方式重写你的代码(仅适用于PhpStorm ......没办法)。

您的代码和PHPDoc很好 - 这是一个IDE问题 - 它暂时(仅在该方法内)用您检测到的类型提示覆盖手动提供的类型提示(在其他方法中它将正常工作)。请投票:http://youtrack.jetbrains.com/issue/WI-17047

相关问题