Hello all,
Can someone please tell me if there is a way to declare variables
within a class that can be shared among each new object created from
this class?
For instance I have the following:
class DB {
var $db;
var $host;
var $un;
var $pw;
var $connected;
var $connections;
function DB() {
$host="myserver .com";
$un="username";
$pw="password";
$this->db=null;
}
function Connect($databa se) {
if(!$connected) {
/* do your connection stuff….. */
$connected=true ;
$connections=1;
}
$this->db=$database ;
$connections++;
}
}
so that the variable $db which holds the name of the currently
selected database will change with each instance of an object being
created from this class, but the variable $connected and $connections
will be shared between each instance of an object.
Thank you in advance for your answers.
Anthony
Can someone please tell me if there is a way to declare variables
within a class that can be shared among each new object created from
this class?
For instance I have the following:
class DB {
var $db;
var $host;
var $un;
var $pw;
var $connected;
var $connections;
function DB() {
$host="myserver .com";
$un="username";
$pw="password";
$this->db=null;
}
function Connect($databa se) {
if(!$connected) {
/* do your connection stuff….. */
$connected=true ;
$connections=1;
}
$this->db=$database ;
$connections++;
}
}
so that the variable $db which holds the name of the currently
selected database will change with each instance of an object being
created from this class, but the variable $connected and $connections
will be shared between each instance of an object.
Thank you in advance for your answers.
Anthony
Comment