是否有必要将方法定义为“公共”?
如果所有方法都是公共的,除非它们被明确定义为其他方法,那么是否有必要将方法定义为public
?
If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,您已经通过命名默认值回答了问题:不,没有必要。
引用手册:
不过,我认为始终这样做是一种很好的做法。
Well, you answered the question already by naming the default: no, it is not necessary.
To quote the manual:
However, I consider it good practise to always do so.
因为
public
是默认值,因此没有必要定义它。Because
public
is the default it isn't necessary to define it.php 有两种风格倾向 - “javaesque”大多数人认为可见性修饰符非常重要并积极使用它们,而在 pythonesque 少数派(我个人属于)中,我们认为所有公共-私有-接口-抽象的东西只不过是浪费内存。
There are two style tendencies in php - the "javaesque" majority considers visibility modifiers very important and uses them actively, in the pythonesque minority (i personally belong to) we think that all that public-private-interface-abstract stuff is nothing more but a waste of RAM.