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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -