best way to call function from an extended class

佐手、 提交于 2019-12-12 04:52:39

问题


I am using phpstorm as IDE. And in my class.php, I started the class as

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

the query() is in the class 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 is working without any problem.

Is there any problem with this code style? Or Do I need to try a different approach? I searched many websites. But didn't get a proper answer. Please help. Thank you.


回答1:


The problem is you need everything in classes to be called from a method or outside of the class after the class is instantiated.

you cannot use $this outside the method scope in a class

EDIT, OP changed question :

works fine for me, no warning




回答2:


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

Is this working?



来源:https://stackoverflow.com/questions/26295819/best-way-to-call-function-from-an-extended-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!