Best way to call a function from an extended class

I use phpstormas an IDE. And in mine class.phpI started class as

class MyClass extends Database{
    function sample(){
        $this->query();
    }
}

query()is in the classroom Database. But phpstorm shows a warning that

Method 'query' not found in class MyClass. Referenced method is not found in subject class. 

But the function works without problems.

Are there any issues with this code style? Or do I need to try a different approach? I have searched many websites. But did not receive the correct answer. Please help. Thank.

0
source share
2 answers

The problem is that you need everything in the classes called from the method or outside the class after creating the class instance.

you cannot use $thisoutside the scope of a method in a class

EDIT, OP changed the question:

works great for me, no warnings enter image description here

0
source
class MyClass extends Database{
   function sample(){
       parent::query();
   }
}

It works?

0
source

Source: https://habr.com/ru/post/1599007/


All Articles