D
D
Dubrovin2019-09-05 11:58:54
phpstorm
Dubrovin, 2019-09-05 11:58:54

How to associate a file with a class?

In a separate file, MyClass.php, there is a class with two methods:

<?php
class MyClass {
    public function render() {
        require template.php
    }

    public function method1() {
        //some code here
    }
}

In the template.php file, we call method1 via $this->method1:
<?php
$this->method1();

PHPStorm does not understand that $this in this context is an instance of the MyClass class and therefore writes "Unused element" in the class file when hovering over the method1 method, and the transition by CTRL + click on the call to the $this->method1() method does not work;
What phpdoc comments need to be written for this to work as it should? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Konyukhov, 2019-09-05
@Dubrovin

As an option in template.php after the opening php tag add the ward /** var $this MyClass */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question