Autocompletes inside of included HTML files

This is difficult to phrase, but what I would like to know is if it is possible for a php file to have auto completes enabled for class methods even if that file does not mention the class This is possible if I add $variable = new Object(); to a file directly, but in this case, it is not desirable to do so.

In particular, I have nearly pure html files that are included by objects (view files in an mvc pattern). In these files, I can run use $this->objectMethod, and it works in php, but no auto completes are generated. Clearly, phpstorm cannot find the unspecified object, which makes sense. But I am wondering if I can set some flag or otherwise make phpstorm treat a certain group of files AS IF a class/object has been instantiated within them, so I can get autocompletes in these files.

(I hope this is clear.)

Comment actions Permalink

Hi there,

Use PHPDoc comments for that.

/** @var MySpecialClass $this */
<h1><?php echo $this->printHeader(); ?></h1>

Comment actions Permalink

That did it - thanks!

I guess I am unfamiliar with how phpdoc works with php storm. Is there documentation for this?

I tried the above links but they are quite basic. I guess I could save myself a lot of time if I knew how I could get php storm to auto complete in certain situations.

Comment actions Permalink

These are general links. PhpStorm follows phpDocumentor and proposed PSR-5 (maybe not everything, but almost all).

The most "special" feature not really described in aforementioned links (although references are found in PSR-5 doc) is the one I gave you already -- possibility to tell PhpStorm that there is certain variable in this file  (or code block)  and of what type (or redeclare type of that variable)


Please sign in to leave a comment.