如何正确建立类结构

时间:2018-09-19 04:44:47

标签: php oop

我有这堂课

class Base
{
  // This class contains a lot of private method which are using inside this class
  private function CreateRequest()
  {
    //using curl to send request
  }
}

class API_CALLS extend Base
{
  //Here i want to create a static class to make API calls to server, but i need to use create request method from base class
  static public get_name()
  {
    $params = array();
    $this->CreateRequest($params); // i know this causes the error
  }
}

在我的情况下,创建类结构的最佳方法是什么?

1 个答案:

答案 0 :(得分:-1)

您必须在课堂上知道“ private”,“ static”和“ $ this”的含义。

class Base
{
   protected static function CreateRequest()
   {
    //using curl to send request
   }
}

class API_CALLS extends Base
{

    static function get_name()
    {
    $params = array();
    self::CreateRequest($params); 
    }
}