如果影響,我在建這個調用類的名字:PHP:使用繼承功能,從擴展的類
Class Foo {
$bar = new Bar();
protected function Spoon() {
get_class($this);
}
}
Class Bar extended Foo {
$this::Spoon(); //Should show "Bar", but instead shows "Foo"
}
我希望能夠找到「酒吧」從勺(),但我總是得到父類。 我有點迷路了。我怎樣才能讓這段代碼正常工作?
的功能,您可以重新制定的例子有一個有效的PHP程序(或片斷)? – Artefacto
是'Foo :: Spoon()'是靜態的還是對它的函數調用不正確。看來你正在將Paamayim Nekudotayim(::)與'$ this->'混合在一起。而且,代碼不能在函數的主體中執行。它需要放在一個位置(如'__construct'或),然後調用(或用'new Bar();')實例化。 –