Which convention is more common “static public function” or “public static function” (based on Symfony and Doctrine)

Few minutes ago Brent Shaffer asked on the Twitter

Which is more standard, “public static function” or “static public function”?

I was curious about it, so I’ve checked which convention is used in my favourite Symfony Project. Of course, I haven’t got enough time to check it manually, class by class, so I wrote simple bash script:

egrep "^[^\*/]*static.*function" /usr/share/php/symfony/ -rioh --include=*.php | sed 's/^\s*//g' | sort | uniq  -c | sort -r

The answer  for the Symfony 1.2 was:

685 public static function
181 static public function
27 static protected function
16 protected static function
16 private static function
11 static function
2 abstract public static function

I’ve done same thing for Doctrine ORM Project

egrep "^[^\*/]*static.*function" /usr/share/php/Doctrine/lib/ -rioh --include=*.php | sed 's/^\s*//g' | sort | uniq  -c | sort -r

and the result was:

78 public static function
6 static public function
6 static protected function

Now I can tell that “public static function” is more common, and by the way I use same convention in my classes :-)


Tagi: , , , ,

Podobne wpisy

3 Responses to “Which convention is more common “static public function” or “public static function” (based on Symfony and Doctrine)”

  1. bshafs Says:
    Styczeń 26th, 2010 at 01:22

    Great post! Good thinking. This begs so many questions. What is the standard for the order of these things? Is it always abstract public static? And if so, why? It seems to me this should be arranged in order of importance, which I would see as “abstract static public”. Or, if you consider access modifiers should always be declared, then public/protected/private should always come first. This would look like “private abstract function” or “private abstract static function” which I’ve never seen. Is there not some sort of Zend coding standard for this issue?

  2. Adam Says:
    Luty 23rd, 2010 at 19:11

    AFAIK it’s inspired by Java, so Java Coding Conventions should be applied: public, protected, private, abstract, static, final

  3. online Says:
    Maj 19th, 2010 at 09:34

    Dzieki za ciekawy blog

Skomentuj