The PSR-2 encoding standard explicitly requires the visibility modifier to be used for both properties and methods .
Using public not required, although due to the fact that PHP 5 and 7 are backward compatible with version 4, which has only public visibility for everything, it is therefore the default value.
However, omitting it, you will ask questions - just like you. People are very good at patterns and mistakes. What would you think of a piece of code that uses protected or private everywhere (because you need it), but accidentally omits public . This is mistake? Was this done on purpose? What secret behavior should be caused by this? Or is it still PHP4 code that hides some unpleasant compatibility issues? As a developer, you do not want to ask these questions, and you do not want to find the answers.
public is optional, but PSR-2 decided to require it. Go with the standard recommendation.
Also note that there was a suggestion to remove and remove the var modifier for properties and completely replace it with public . The proposal also contains code analysis of the top 10,000 Packagist packages, which indicates that 94% of all classes in this code base use public exclusively, the remaining 6% of classes using var come from four large packages, which are likely to continue try to be compatible with PHP4, and "Simpletest" (the unit test framework focused on PHP 4) leads.
There is no such static code analysis for visibility modifiers for methods that I know about, but the trend is clearly noticeable: get rid of old PHP4-isms.
source share