oop - PHP Child class accessing object in Parent class -


class bm_main {      public $db;      public function __construct(){          $this->db = new db();     }  }  class bm extends bm_main{      public function __construct($id){         $this->db = parent::$db;             $this->db->save($id);     } } 

how access $db object parent class can use in child one

call parent constructor db class instantiated:

    public function __construct($id) {         parent::__construct();         $this->db->save($id);     } 

the $db property inherited subclass, , public, can access using $this->db.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -