oop - Call parent constructor automatically after children PHP -


i tried name of parent class constructor , works partially me.

first calls

"darthvader method"

like constructor never call

"lukeskywalker constructor"..

somebody knows how it?

example:

darth.php

class darthvader{     public function darthvader(){         echo "-- obi-wan never told happened father.\n";     }     public function reponse(){         echo "-- no. father\n";     } } 

luke.php

include("darth.php")  class lukeskywalker extends darthvader{  public function __constructor(){         echo "- told me enough! told me killed him!\n"         $this->response();     } } 

expected result:

  • obi-wan never told happened father.

  • he told me enough! told me killed him!

  • no. father

i so, automatically.

as per documentation: http://php.net/manual/en/language.oop5.decon.php

note: parent constructors not called implicitly if child class defines constructor. in order run parent constructor, call parent::__construct() within child constructor required. if child not define constructor may inherited parent class normal class method (if not declared private).


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -