这是父类:
class Event {
public function getLang($lang){
$sql = "select * from Event where EventID =" . $this->EventID . "AND Lang =" . $lang;
$result = $this->selectOneRow($sql);
}
}
这是 child :
class Invitation extends Event{
public function getLang($lang){
Event::getLang($lang);
$sql = "select * from invitation where EventID =" . $this->EventID . " and Lang = " . $lang;
}
}
我曾希望 EVENT::getLang($lang) 能正常工作,但在我回显查询后,我发现它没有 EventID。
有没有正确的方法来做到这一点?
我尝试直接复制/粘贴子代码,但这也行不通,因为我在父级获得了事件选择结果将分配给的变量。
有什么办法可以解决这个问题,还是我陷入了僵局?
最佳答案
我认为您希望使用 parent
关键字:
class Invitation extends Event{
public function getLang($lang){
parent::getLang($lang);
$sql = "SELECT * FROM invitation WHERE EventID =" . $this->EventID . " AND Lang = " . $lang;
}
}
关于php 多态性 - 在多态子函数中调用父函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5077728/