Jump to content

Classes and global variables....


sathyendra

Recommended Posts

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

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';
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.