PhpStorm / PhpDoc类型提示在魔法对象中返回变量

问题描述 投票:4回答:1

我有一个类测试和它getData返回一个神奇地在方法的上下文中出现的对象变量。

我的问题是如何正确地使用ohintovat到IDE并且phpdoc被告知是正确的。我想让PhpStorm了解他作为输出变量返回的内容。可以?

class Test
{

    /**
     * @param $param
     * @return object
     */
    function getData($param)
    {

        // .......

        $data = (object)[
            'a' => 'aaa',
            'b' => 'bbb',
        ];

        return $data;
    }

}


$test = new Test();
$data = $test->getData('param');

echo $data->

enter image description here

php phpstorm type-hinting hint
1个回答
0
投票

我建议你使用额外的模型类来解决它。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.