Emanuil Rusev
Emanuil Rusev

Reputation: 35265

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

If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public?

Upvotes: 3

Views: 212

Answers (3)

user187291
user187291

Reputation: 53940

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.

Upvotes: 1

Gordon
Gordon

Reputation: 317119

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.

Upvotes: 11

fabrik
fabrik

Reputation: 14365

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

Upvotes: 1

Related Questions