How to call non-static method from static method of same class?

后端 未结 3 1557
暗喜
暗喜 2021-01-31 07:36

I am working on PHP code.

Here is the sample code to explain my problem:

class Foo {

    public function fun1() {
             echo \'non-static\';   
         


        
3条回答
  •  盖世英雄少女心
    2021-01-31 08:11

    The main difference would be that you can call static methods for a class without having to instantiate an object of that class. So, in your static method try

    Foo $objInst = new Foo();
    $objInst->fun1();
    

    But I don't see how this would make any sense in any context.

提交回复
热议问题