A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 year“public static” or “static public”? - page 1
User InfoPosts
“public static” or “static public”?#1
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.)

posted date: 2009-04-16 10:24:00


Re: “public static” or “static public”?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-16 10:24:01


Re: “public static” or “static public”?#3
I don(t think that this is a strictly PHP question, and for what little it(s worth, I(ve always preferred the consistency of placing the visibility modifier first. I find it easier to scan.

posted date: 2009-04-16 10:25:00


Re: “public static” or “static public”?#4
I put visibility first in every language I use that has type modifiers.

posted date: 2009-04-16 10:31:00


Re: “public static” or “static public”?#5
Neither Java nor C# require this. I believe they recommend it, but "static public" is valid in both languages. (I've just compiled a test program to check.)

posted date: 2009-04-16 10:41:00


Re: “public static” or “static public”?#6
(Undone my downvote though, as the rest is fair enough - and I certainly agree that "public static" looks more reasonable.)

posted date: 2009-04-16 10:43:00


Re: “public static” or “static public”?#7
Yikes! My mistake - you are correct!

posted date: 2009-04-16 10:47:00


Re: “public static” or “static public”?#8
You are correct in that it has no effect on the code. Therefore it is up to your own style requirements, or those of your team, as to what you do. Consult with them and agree on a style.If you are coding for yourself only, then you should choose for yourself. The choice is not important, but consistency is.Another question you may ask is: should you use (public( or not? For backwards compatibility (PHP4 had no information hiding) anything without a visibility modifier is public by default. Should you bother writing public if it(s public? Again personal choice: make a strong argument either way and you(ll convince me your choice is best.Personally, when I go through and clean up my own code, I like to put the visibility modifier first, and specify it even if it(s public.

posted date: 2009-04-17 09:33:00


Re: “public static” or “static public”?#9
I've considered omitting 'public' since it's technically redundant, but I find it's better to be explicit. That way when I come back to my code six months later, I don't have to wonder why there's no access keyword on method foo(); did I just forget to put one there, or did I mean for it to be public?

posted date: 2009-05-07 09:42:00


Re: “public static” or “static public”?#10
good point ☻

posted date: 2009-05-07 21:34:00


Re: “public static” or “static public”?#11
I prefer static public since this way it is easier to spot [usually rare] static methods in classes.

posted date: 2009-10-01 21:11:00


Re: “public static” or “static public”?#12
I was going to write this as an answer. I totally agree.

posted date: 2012-04-01 08:42:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.