在类方法中调用函数?

2021-12-23 00:00:00 function class methods call php

我一直在想如何去做,但我不太确定如何去做.

I have been trying to figure out how to go about doing this but I am not quite sure how.

这是我正在尝试做的一个例子:

Here is an example of what I am trying to do:

class test {
     public newTest(){
          function bigTest(){
               //Big Test Here
          }
          function smallTest(){
               //Small Test Here
          }
     }
     public scoreTest(){
          //Scoring code here;
     }
}

这是我遇到问题的部分,我如何调用 bigTest()?

Here is the part I am having problems with, how do I call bigTest()?

推荐答案

试试这个:

class test {
     public function newTest(){
          $this->bigTest();
          $this->smallTest();
     }

     private function bigTest(){
          //Big Test Here
     }

     private function smallTest(){
          //Small Test Here
     }

     public function scoreTest(){
          //Scoring code here;
     }
}

$testObject = new test();

$testObject->newTest();

$testObject->scoreTest();

相关文章