doulong6761 2018-02-12 09:03
浏览 20

从子类调用函数

Given I have an abstract class:

abstract class User{

  private function getNumber(){

      return 'Get number';
  }
}

With the child class

class UserComments extends User{


   public function rows(){
    return $this->getNumberOfRows();
 }
}

Question:

Is there any way to call the getNumber function when I try to call getNumberOfRows method in child class, or when I call getNumberOfRows() in child class I want getNumber to be called instead ?

  • 写回答

3条回答 默认 最新

  • doutou7740 2018-02-12 09:11
    关注

    Due to PHP's Object inheritance you can directly call the specific method. However, in your example the getNumberOfRows() function is missing.

    class UserComments extends User {
    
       public function rows() {
          return $this->getNumber();
       }
    }
    
    评论

报告相同问题?