Possible to tell PHPStorm that a script is included by another script?

I have a custom framework based on MVC where the view files get included by the controller files. PHPStorm does not appear to see how the files are related, and so marks all of the variables in the view file as undefined. Is there a way to tell PHPStorm either what script(s) will be including a file, or where specific variables are defined?

Comment actions Permalink

Hi William,

If those variables are global and unique, then PhpStorm should see them with no issues. But if they are local or are declared/created in a lot of places (e.g. on every controller), then the only thing ATM that can help is to declare them in template using PHPDoc syntax, e.g.

/** @var $db MyDBClass */
/** @var $data MyDataHolderClass */
<div id="contact-us">
  <?php echo $data->doSomething(); ?>

Obviously, such view files should be associated with PHP in Settings | File types (in case they have non-standard extension).

Comment actions Permalink

Ok, thanks. Is there a good reference to how PHPStorm uses the doc comments that you might be able to point me to? I've noticed that there are some nuances to how classes need to be entered and the use of @internal and @var and I'd like to get as familiar with it as I can.


Comment actions Permalink

No reference is available.
First you should to follow the PHPDoc conventions http://manual.phpdoc.org/HTMLframesConverter/default/ and provide all possible metadata.
Then there's some logic specific to how type inference and code inspection works in PHPStorm - this is moving target and actually improves with each release.


Please sign in to leave a comment.