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

If all methods are publicly available, if they are not explicitly defined as something else, should the method ever be defined as public?

+3
source share
3 answers

Well, you already answered the question by specifying by default: no, this is not necessary.

To quote the manual :

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

However, I think this is always good.

+11
source

public , .

+1

There are two style trends in php: "javaesque" the majority considers visibility modifiers to be very important and actively use them, in the Pitonesian minority (I personally belong) we consider that everything that is a public-private interface is nothing more than memory loss.

+1
source

Source: https://habr.com/ru/post/1765054/


All Articles