"public static" or "static public"? "public static" or "static public"? php php

"public static" or "static public"?


From PSR-2:

Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility. [reference]

...if you are one to care about the PHP Framework Interop Group standard and conventions.

So public static not static public according to them.


Languages like Java and C# require that the access modifier come first so Edit: The previous struck line is completely false. Neither language has this requirement.


public static

looks correct to me. Arguments can be made for both approaches and mine is this: Since "static" qualifies the function rather than the access modifier it makes more sense to say

<access_modifier> static

If you use it the other way around the meaning of "static" is less clear.


Further to Alexei Tenitski's answer.

I prefer static public since this way it is easier to spot [usually rare] static methods in classes.

All methods ought to have their visibility specified. So, we know that every method is going to have that mentioned somehere in the definition, the only question is "Which setting is it?".

Only some are static - so, for each one we have to ask "Is there a mention of the static keyword somewhere in the definition?". So, put static first to make the answer to that question more obvious.

Or, as a wider rule , ......... I tend to put 'the most extraordinary aspect first' so that I don't don't subsconsciously skip over things when reading them. ;o)

Try this test.

Very quickly...How many static methods are there in Class A?

class A { public static methodA() {  } protected static methodB() {  } private staticlymethodC() {  } }

and how many static methods are there in Class B?

class B { public methodA() {  } static protected methodB() {  } static private methodC() {  } }

I think class B is much easier to understand quickly.