Page 1 of 1

Help - Inheritance

Posted: Thu May 13, 2010 3:28 am
by michaeru
Good day,

I have two classes, one inherits (extends) the other class.

Code: Select all

class A {

  public function __construct {

    $this->do_this();
    $this->do_that();

  }

  protected function do_this()  {
    ...
  }

  protected function do_that() {
    ...
  }

}

Code: Select all

if(!class_exists('A')) {

  require_once('A.class.php');

}

class B extends A {

  public function __construct() {

    $this->do_those();
    $this->do_this();
    $this->do_that();

  }

  private function do_those() {
    ...
  }

}

$trial = new B();
Now when I try the class, I get something like this.

[text]Fatal error: Call to private method A::do_this() from context 'B' in C:\xampp\htdocs\B.class.php on line 12[/text]

Protected methods are available to subclasses, right?

Re: Help - Inheritance

Posted: Thu May 13, 2010 1:53 pm
by Christopher
Yes, but the error message says it is declared private. Are you sure you are looking at the file that is actually being included?