Calling a function within a Class method?

前端 未结 10 1053
庸人自扰
庸人自扰 2020-12-02 05:14

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 {
          


        
10条回答
  •  情深已故
    2020-12-02 05:55

    The sample you provided is not valid PHP and has a few issues:

    public scoreTest() {
        ...
    }
    

    is not a proper function declaration -- you need to declare functions with the 'function' keyword.

    The syntax should rather be:

    public function scoreTest() {
        ...
    }
    

    Second, wrapping the bigTest() and smallTest() functions in public function() {} does not make them private — you should use the private keyword on both of these individually:

    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;
        }
    }
    

    Also, it is convention to capitalize class names in class declarations ('Test').

    Hope that helps.

提交回复
热议问题