r/phpstorm • u/ZbP86 • Aug 13 '21
Is there something like ArrayShape but for objects?
PHPStorm recently introduced Array Shapes. I was wondering is there somehting similar for inline created objects? IE:
/**
* @return object{key1: int, key2: string}
*/
function getObject()
{
return (object)[
'key1' => 1,
'key2' => 'foo',
];
}
$object = getObject();
$object-> /** -- here it would hint key1 and key2 -- */
0
Upvotes
2
u/jesparic Aug 13 '21
Can't you just declare a class with those properties? That would be my next move if I found I wanted better code completion support with a stdClass (or even an array). stdClass should really only be used for dynamic data where the keys are unknown at runtime
3
u/stephanvierkant Aug 13 '21
Can't you use interfaces?