Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm auto-complete support for unknown object properties managed by Pimple?

I have the following code in an application powered by Silex:

$uknownObj->unkownRef

$uknownObj being a dependency injection container.

I know that unkownRef is of instance MyCoolObj.

Now how can I tell IntelliJ / PhpStorm to actually help me with autocomplete of this said object?

like image 485
Toskan Avatar asked Mar 19 '26 01:03

Toskan


2 Answers

Simply assign unkownRef to a variable and provide annotation like this.

/** @var MyCoolObj $obj */
$obj = $uknownObj->unkownRef;
like image 86
mansoor.khan Avatar answered Mar 20 '26 16:03

mansoor.khan


You can either use phpdoc comments as suggested by xmoex, or assert type with instanceof:

enter image description here

like image 45
Alex Blex Avatar answered Mar 20 '26 17:03

Alex Blex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!