"public static" or "static public"?

dirtside picture dirtside · Apr 16, 2009 · Viewed 25k times · Source

A minor point about function declaration keywords in PHP: If you've got a class method that's static, should the static keyword come before or after the visibility keyword (public, protected, private)? Assuming all your methods, static or otherwise, have a visibility keyword, then you'd want the visibility keyword to remain in the same place relative to the function keyword:

public function foo() {}

public function bar() {}

protected function baz() {}

private function quux() {}

Now pretend a couple are static:

public function foo() {}

static public function bar() {}

protected function baz() {}

static private function quux() {}

Also, if a method is static, you want that to be the first thing seen, because that has more of an impact on what kind of method it is than even the visibility keyword does.

This is strictly a readability issue, as it obviously has no functional or design consequences. (That I can think of.)

Answer

PressingOnAlways picture PressingOnAlways · Aug 29, 2014

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.