phpautocompletephpstormdocblocks

PhpStorm, docblock with object shape


I want to define object shape for autocompletion in PhpStorm.

for example:

$myobject = json_decode("{id:1, price:123.99}");

for arrays exists docblock:

/**
 * @var array{id: int, price: float}
 */
$myArray = json_decode($jsonString, true);

and when I type:

$myArray[''] 

IDE autocompletes it to id | price

I want to do it in a similar way for objects:

/**
 * @var object|stdClass{id: int, price: float}
 */
$myObject = json_decode($jsonString, false);

and get autocomplete when I type

$myObject->

Solution

  • Not supported by PhpStorm yet as fas as I'm aware.

    https://youtrack.jetbrains.com/issue/WI-66396 -- watch this ticket (star/vote/comment) to get notified on any progress. Once implemented it will be coming as a part of Psalm plugin.