1
A類的bar函數需要調用A類的foo函數。 對於A的一個實例,$ this-> bar()起作用。 對於B的情況下,這 - $>巴()不工作,它創建了一個環路B-FOO - A-吧...PHP - 在子實例中調用父函數的父函數
class A {
function foo() {
(...)
}
function bar() {
$this->foo();
(...)
}
}
class B extends A {
function foo() {
parent::bar();
(...)
}
function bar() {
$this->foo();
(...)
}
}
我想這樣的解決方法爲 'A' 酒吧函數,但得到錯誤:「噹噹前類作用域沒有父代時不能訪問父::」
class A{
function bar(){
switch (get_class($this))
{
case "A" : $this->foo() ; break;
case "B" : parent::foo(); break;
}
}
}
任何想法如何做到這一點?
感謝
'自:: foo的();''在A'? – JustOnUnderMillions