oop - How to access other classes methods within a class (PHP) -


i'm building php oop mvc framework personal use.

i'd know if there's way or correct implementation of following:

being able call method "subclass" (not extended) "subclass". mean... have class creates new objects each subclass instead of using inheritance. let's call mainclass, , has 3 "subclasses" this

class mainclass {     public $db;     public $forms;     public $pagination;      function __construct() {         $this->db = new class_db();         $this->forms = new class_forms();                $this->utils = new class_utils();     }    } 

and initialization is

$mainclass = new mainclass(); 

i can example

$mainclass->utils->show_text("hello world"); 

and works fine.

what i'd is... within $mainclass->utils->test() (another test method), able access $mainclass->db without using global or $globals.

is there alternative way of achieving this? able access $mainclass methods , submethods within submethod (access db utils , main page mainclass initialized)? how be? want able access al submethods, utils being able access db , forms method. pages outside mainclass.

thank you

if utils has use db, either have pass mainclass instance utils, can call $this->myreftomain->db, or pass instance of db itself, utils can call $this->db. either way, cannot (reasonably) crawl call stack find object called it.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -