php - How do you access a child method -
how access child method eg.?
class { public function start() { // somehow call run method on b class inheriting class } } class b extends { public function run() { ... } } $b = new b(); $b->start(); // should call run method
class a
should not try call methods not define. work fine scenario:
class { public function start() { $this->run(); } }
however, fail terribly should this:
$a = new a; $a->start();
what you're trying here sounds use case abstract
classes:
abstract class { public function start() { $this->run(); } abstract function run(); } class b extends { public function run() { ... } }
the abstract
declaration precisely prevent shooting own foot trying instantiate , start
a
without extending , defining required methods.
Comments
Post a Comment