简体   繁体   中英

PhpStorm/PhpDoc type-hinting for return variable in a magical object

I have a class test and it getData that returns an object variables that arise in the context of methods magically.

My question is how to properly ohintovat to IDE and phpdoc told was correct. I want to PhpStorm understand what his return as output variables. Does it?

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->

在此输入图像描述

I suggest you to solve it using en extra model class.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM