Type PhpStorm / PhpDoc type for the returned variable in the magic object

I have a class test, and one getDatathat returns object variables that occur magically in the context of methods.

My question is how to correctly IDE and phpdoc said correctly. I want PhpStorm to understand that it returns as output variables. 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->

enter image description here

+4
source share
1 answer

I suggest you solve it using an additional model class.

enter image description here

0
source

All Articles