initialzing base class constructor
Posted: Tue Jun 29, 2004 9:05 am
hi everyone,
can any body help me knowing that how can i initialize the constructor of the base class if an object of the derived class is created.
eg.
class base
{
var x;
var y;
function base()
{
$this->x = 100;
$this->y = 200;
}
}
class derived extends base
{
var p;
var q;
function derived()
{
$this->p = 20;
$this->q = 40;
}
}
Now if i declare an object of the class derived like this:
$obj = new derived();
The above statement initilizes the constructor of the child class which sets the values of p and q to 20 and 40 respectively,
now i am not able to figure out that how can i initialize and access the variables of the base (parent) class by creating an object of the derived class, so that i am also able to access the variables of the parent class with the same object (i.e. object of the child class)
kindly help,
Thanks
Gaurav
can any body help me knowing that how can i initialize the constructor of the base class if an object of the derived class is created.
eg.
class base
{
var x;
var y;
function base()
{
$this->x = 100;
$this->y = 200;
}
}
class derived extends base
{
var p;
var q;
function derived()
{
$this->p = 20;
$this->q = 40;
}
}
Now if i declare an object of the class derived like this:
$obj = new derived();
The above statement initilizes the constructor of the child class which sets the values of p and q to 20 and 40 respectively,
now i am not able to figure out that how can i initialize and access the variables of the base (parent) class by creating an object of the derived class, so that i am also able to access the variables of the parent class with the same object (i.e. object of the child class)
kindly help,
Thanks
Gaurav