How can I tell PHPStorm that this required file is part of a class?

Hello all!

I am trying to build a PHP Framework and I have a View object that receives what I call "chunks".

These chunks are php view files that, when rendering is needed, the View class "requires" and therefore prints.

These php chunk files uses View methods.

Problem? PHPStorm does not know what I am talking about when I call a View method from these chunks.

How I could tell PHPStorm that a file us part of a class?

I will explain myself better with examples.

(Code has been simplified for easier understanding)
    public function printChunk($name)
        require _ROOT_ . "application/views/{$this->_chunks[$name]}.php";

An example Chunk.
<h1>Hello, this is a chunk. </h1>
<?php $this->printChunk('header'); ?>


Hi there,

Just use proper PHPDoc comment for this:


<?php /** @var MyClass $this */ ?>

<h1>Hello, this is a chunk. </h1>
<?php $this->printChunk('header'); ?>

Obviously, you may only call public or (since v7.1) protected methods. Private methods most likely will produce warning anyway (not 100% sure though).


That is just right Andriy! Thank you very much :)


Please sign in to leave a comment.