This Question is Answered

2 "helpful" answers available (2 pts)
2 Replies Last post: Dec 27, 2013 2:39 PM by Hector Ordonez  
Hector Ordonez Newbie 3 posts since
Jul 19, 2013
Currently Being Moderated

Dec 26, 2013 11:25 PM

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)

view.php

    public function printChunk($name)

    {  

        require _ROOT_ . "application/views/{$this->_chunks[$name]}.php";

    }

 

An example Chunk.

index.php

<h1>Hello, this is a chunk. </h1>

<?php $this->printChunk('header'); ?>

Andriy Bazanov Master 4,092 posts since
May 28, 2010
Currently Being Moderated
Dec 27, 2013 12:58 AM in response to: Hector Ordonez
Re: How can I tell PHPStorm that this required file is part of a class?

Hi there,

 

Just use proper PHPDoc comment for this:

 

index.php

<?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).

More Like This

  • Retrieving data ...