PHP call Class method / function

后端 未结 7 444
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 10:47

How can I call following Class method or function?

Let say I have this params get from url:

$var = filter($_GET[\'params\']);

7条回答
  •  旧巷少年郎
    2020-12-09 11:36

    Within the class you can call function by using :

     $this->filter();
    

    Outside of the class

    you have to create an object of a class

     ex: $obj = new Functions();
    
         $obj->filter($param);    
    

    for more about OOPs in php

    this example:

    class test {
     public function newTest(){
          $this->bigTest();// we don't need to create an object we can call simply using $this
          $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();
    

    hope it will help!

提交回复
热议问题