reduce the access level of a function in a derived class
Is there any possibility to reduce the access level of a function in a derived class in PHP?
example (... means more code)
class foo
{
public function myFunction() { ... }
public function myOtherFunction() { ... }
}
class bar extends foo
{
private function myFunction() { ... }
}
Now I should'nt be able to call MyFunc
ion a bar
object. But doing it this way doesn't seem to be valid in PHP. Any other way? I know I could impl开发者_如何学Cement an empty function but I don't want to expose the function in the interface at all.
Its not valid in OOP anyway. If you implement a public method, you promise, that this class and all children provides this functionality. To remove a public method means, that you break your promises ;) Because all public methods and properties define the interface of the class and breaking an interface is never a good idea.
Without any clearer information about what you are going to do I suggest to just throw an exception, something like "Not supported".
精彩评论