sathyendra Posted June 17, 2008 Share Posted June 17, 2008 Hi, i have 2 classes 1) class DB{ ....... .... .. .. } 2) class cms{ function header(){ } function footer(){ } function body(){ $db = new DB(); ....... .... .. .. } } what i want is i want to some variables in body function to be accassible in header function(the values will be retrived from database using DB class object in the body function ) ... please suggest ... Thanks & Regards, Satya Link to comment https://forums.phpfreaks.com/topic/110564-classes-and-global-variables/ Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 class cms{ var $info; var $moreinfo; function header(){ echo $this->info; } function footer(){ echo $this->moreinfo; } function body(){ $db = new DB(); $this->info = 'abc'; $this->moreinfo = 'def'; } } Link to comment https://forums.phpfreaks.com/topic/110564-classes-and-global-variables/#findComment-567224 Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 also, if you are new to PHP and OOP, give this a read through, it should help you a lot: http://devzone.zend.com/node/view/id/638 Link to comment https://forums.phpfreaks.com/topic/110564-classes-and-global-variables/#findComment-567226 Share on other sites More sharing options...
keeB Posted June 21, 2008 Share Posted June 21, 2008 <?php class CMS { private $var1; private $var2; public function header() { $this->var1 = "i was set in header"; } public function body() { echo $this->var1; } } $c = new CMS(); $c->header(); $c->body(); Link to comment https://forums.phpfreaks.com/topic/110564-classes-and-global-variables/#findComment-571218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.