开发者

Is it ever necessary to define a method as "public"?

If all methods are public unless they are explicitly d开发者_StackOverflow中文版efined as something else, is it ever necessary to define a method as public?


Well, you answered the question already by naming the default: no, it is not necessary.

To quote the manual:

Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.

However, I consider it good practise to always do so.


Because public is the default it isn't necessary to define it.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜