Understanding inheritance in php

I am new to using OOP in PHP (and generally) and I have a question about inheritance.

I have the following classes:

class OCITable {
  public function display() {
    $this->drawHeader();
    $this->drawFooter();
    $this->drawBody();
  }

  private function drawHeader() {
    ...
  }

  private function drawFooter() {
    ...
  }

  private function drawBody() {
    ...
  }
}

class OCITableServer extends OCITable {
  private function drawBody() {
    ...
  }
}

What I'm trying to do is cancel a private function drawBody(). This does not seem to work. I think this is because when the object OCITableServercalls display(), it calls the parent class display(), which in turn calls it drawBody()instead of the new one drawBody().

How do I accomplish what I'm trying to do without overriding display()in my subclass?

+3
source share
1 answer

Protectedmethods can be overridden in subclasses. Private functions cannot.

+4

Source: https://habr.com/ru/post/1760831/


All Articles