如何防止在foo類中創建以下something
方法?如何不允許在PHP中定義子類方法
class fooBase{
public function something(){
}
}
class foo extends fooBase{
public function __construct(){
echo $this->something(); // <- should be the parent class method
}
public function something(){
// this method should not be allowed to be created
}
}
可以'__construct'方法是最終的太(如果fooBase有一個)? – Alex 2011-06-06 08:18:19
是的,__construct可以是最終的。如果你說在父母課堂上是最終的,你就不能在孩子身上有一個。 – SamT 2011-06-06 08:26:33
事實上,正如SamT所說,你可以最終做出__construct。 – MGwynne 2011-06-06 08:37:10