How to access child method
2 answers
A class A
should not attempt to call any methods that it does not define itself. This will be fine for your scenario:
class A {
public function Start() {
$this->Run();
}
}
However, it will fail if you actually do this:
$a = new A;
$a->Start();
What you are trying to do here is very similar to the usage for classes abstract
:
abstract class A {
public function Start() {
$this->Run();
}
abstract function Run();
}
class B extends A {
public function Run() {
...
}
}
The declaration abstract
will definitely prevent you from shooting your own leg trying to instantiate and Start
A
without extending and defining the required methods.
+7
source to share