简体   繁体   English

PHP静态方法可以合法地具有受保护或私有的可见性吗?

[英]Can PHP static methods legally have a visibility of protected or private?

I realize that it's possible to define a static class method as private and protected in PHP. 我意识到可以将静态类方法定义为私有并在PHP中受保护。 This allows for an instantiated class, or public static method to access it's own private/protected static methods. 这允许实例化的类或公共静态方法访问它自己的私有/受保护的静态方法。

protected static function jumpOver  ()

However I'm not sure if this is legal in the sense of OOP design. 但是我不确定这在OOP设计意义上是否合法。 I can't find any real info stating it's ok to do this. 我找不到任何真实的信息,说明这样做是可以的。 I'm worried PHP may "patch" this in future versions if this is not a valid and break my scripts. 我担心PHP可能会在未来的版本中“补丁”这个,如果这不是有效的并打破我的脚本。

It is. 它是。 Static methods are usually nothing more than helper methods that have code you possibly don't want to be public. 静态方法通常只是具有您可能不希望公开的代码的辅助方法。

The other common object-oriented languages I can think of have it too (C++, Java, C#). 我能想到的其他常见的面向对象语言也有它(C ++,Java,C#)。 I really don't think they're ever going to remove that feature. 我真的不认为他们会删除该功能。

Besides, the guys at PHP are slow at breaking existing features, so I wouldn't worry too much about it. 此外,PHP的人在破坏现有功能方面进展缓慢,所以我不会过分担心它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM