SOLVED php object question
Posted: Fri May 02, 2008 12:02 pm
lets say I want to uniquely identify each object class. Each one will have a mykey ID. In this example
parent::printmykey() will also print 2. I was expecting 1, but I guess as soon as the key is redefined in the child the parent value is lost. Is there a way to get 1 from the parent::printmykey() call?
(hint without redifining the printmykey function)
parent::printmykey() will also print 2. I was expecting 1, but I guess as soon as the key is redefined in the child the parent value is lost. Is there a way to get 1 from the parent::printmykey() call?
(hint without redifining the printmykey function)
Code: Select all
class myparent
{
var $mykey=1;
function printmykey()
{
echo "PARENT KEY=" . $this->mykey;
}
}
class child extends myparent
{
var $mykey=2;
function printmykey()
{
echo "CHILD DATA=" . $this->mykey;
}
function printparentkey()
{
parent::printmykey();
}
}
$c = new child();
$c->printmykey();
$c->printparentkey();