Gustavo Novaes
Gustavo Novaes

Reputation: 17

PhpStorm 8.0 - How enable code completion in another file?

I implement MyClass containing the method method() and I store the instance in $_ENV['key'] in test.php. Also in test.php the code completion works when I type $_ENV['key']->.

In test2.php I include test.php and the code completion does not work any more for $_ENV['key']->.

enter image description here

Does anyone know how to enable this in PhpStorm?

Upvotes: 1

Views: 352

Answers (1)

LazyOne
LazyOne

Reputation: 165148

AFAIK type tracking for arrays works within the same file only.

You can bypass it via intermediate variable (yes, it's not a nicest solution) and small PHPDoc comment, like this:

/** @var MyClass $myVar */
$myVar = $_ENV['key'];
$myVar->

P.S. In general, I'd suggest not using global arrays this way (or even not using global vars at all -- only very basic stuff during bootstrap, if possible). Instead (based on your code) I may suggest using some static class (as one of the alternatives) with dedicated field where you can easily give type hint (via PHPDoc) to a class field -- this way IDE will always know hat type it is. Current PHP versions (5.5 and especially 5.6) work with objects nearly as fast as with arrays, even leading in (smaller) memory consumption.

Obviously, such suggestion does not really apply if this code is not yours.

Upvotes: 1

Related Questions