-2

I don't want to use new in my calling php document. I just want to call static method.

For example my class is:

class MergeCaching{

    public static function writeList(){
        $write = new MergeCaching();   // I want to use new here
        $write->getListFromRu();
    }

    public function getListFromRu(){
       print_r('Example');
    }
}

My calling php document like this:

MergeCaching::writeList();

It works but can I use like this?

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
devugur
  • 1,339
  • 1
  • 19
  • 25

1 Answers1

0

If your question is about instantiating a class in its context you could do it using new self:

public static function writeList(){
    $write = new self;
    $write->getListFromRu();
}

Documentation

postrel
  • 134
  • 8