php - Can an instance that is a property of an instance access the other properties of the main instance? -


suppose have following (php reference)

myclassa{     private $myclassb;     private $myclassc;      function __construct(){         $this->myclassb = new myclassb();         $this->myclassc = new myclassc();     } } 

and let's myclassb database connection manager establish , close connections, never write or read connections.

i want write myclassc database connection being managed through myclassb. let's myclassc has function called save_user() saves user data.

is possible save_user contain code references instance of myclassb inside myclassa. example if know myclassc ever created inside myclassa , myclassa have myclassb manage connections, possible myclassc contain line of code such

//$this refers myclassc  $connection_to_write_to = $this->object_im_inside_of->myclassb->db_connection_1->; 

i guess i'm wondering if functions inside myclassc able access properties of myclassa directly or must do

myclassc->myfunction(myclassa->property_i_want) 

to access properties of myclassa want use in myclassc.

in classc definition, should do:

class classc {     private parentclassb;      function __construct($classb) {         $this->parentclassb = $classb;     }     ... } 

then classa constructor like:

function __construct(){     $this->myclassb = new myclassb();     $this->myclassc = new myclassc($this->myclassb); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -