Php 类内:从函数B访问函数a

Php 类内:从函数B访问函数a,php,Php,我有一个问题,这可能不是你们大多数人的问题。 对不起,如果这对你来说是显而易见的 这是我的代码: class Bat { public function test() { echo"ici"; exit(); } public function test2() { $this->test(); } } 在我的控制器中: bat::test2(); 我有一个错误: 异

我有一个问题,这可能不是你们大多数人的问题。 对不起,如果这对你来说是显而易见的

这是我的代码:

class Bat
{
      public function test()
      {
        echo"ici";
        exit();
      }

      public function test2()
      {
        $this->test();
      }
}
在我的控制器中:

bat::test2();
我有一个错误:

异常信息:消息:方法“test”不存在,已被删除 没有被困在调用()中


Bat::test2指的是一个静态函数。所以你必须声明它是静态的

class Bat
{
      public static function test()
      {
        echo"ici";
        exit();
      }

      // You can call me from outside using 'Bar::test2()'
      public static function test2()
      {
        // Call the static function 'test' in our own class
        // $this is not defined as we are not in an instance context, but in a class context
        self::test();
      }
}

Bat::test2();
否则,您需要一个
Bat
实例,并调用该实例上的函数:

$myBat = new Bat();
$myBat->test2();

FbHelper和Bat有什么关系?