开发者

reduce the access level of a function in a derived class

开发者 https://www.devze.com 2023-01-30 05:49 出处:网络
Is there any possibility to reduce the access level of a function in a derived class in PHP? example (... means more code)

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号