我有如下的类层次结构。
class foo()
{
function __construct($dfnname) {
$this->callf = $dfnname;
}
function getd()
{
return call_user_func($this->callf);
}
function retrieve()
{
return $this->getd();
}
}
class bar extends foo
{
function getd()
{
return 'invalid call';
}
function getc()
{
return 'valid call';
}
}
$ins = new bar('getc');
echo $ins->retrieve();
我得到了答案'invalid call'。我想得到“有效通话”的答案。
可能是因为 from 函数foo=>retrieve(),它调用了$this->getd(). 而这里不是调用foo=>getd(),而是直接调用bar=>getd(),我应该怎么做才能调用foo=>getd(),foo=>retrieve()也 应该调用函数call_user_func($this->callf)。foo=>getd()bar=>getc()
我知道我缺少一些基本的继承概念。请指导我。