RE: [PHP] "public static" or "static public"?
| From: | Bob McConnell | Date: | Mon, 31 Jan 2011 14:31:24 +0000 |
| Subject: | RE: [PHP] "public static" or "static public"? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311099@lists.php.net to get a copy of this message | ||
From: Richard Quadling
> On 28 January 2011 17:15, Colin Guthrie <gmane@colin.guthr.ie> wrote:
>> OK, so it's a Friday hence a random debate....
>>
>> What is preferred for class methods?
>>
>> class foo
>> {
>> static public function bar(){}
>>
>> public static function wibble(){}
>> }
>>
>> ??
>>
>> All methods are valid, but are some more valid than others? :p
>>
>> Checking ZF:
>>
>> [colin@jimmy Zend (working)]$ cgrep "public static function" . |wc -l
>> 755
>> [colin@jimmy Zend (working)]$ cgrep "static public function" . |wc -l
>> 60
>>
>> It's clear which is preferred there, but still not absolutely consistent
>> (I didn't bother checking differently scoped methods).
>>
>>
>> I personally prefer scope first then "static", but others may have valid
>> reasons/arguments for preferring the other way.
>>
>> WDYT?
>>
>
> Arrange these 3 words in the "correct" linguistic.
>
> shirt, large, green.
>
> Hopefully, all native English speakers will say
>
> large green shirt.
>
> We just do.
>
> I wonder if the same is true for ...
>
> final public static function
>
> I've just done a quick scan of all my methods ...
>
> 5 abstract protected function
> 2 abstract public function
> 2 final protected function
> 11 final public function
> 1 final public static function
> 1 final static public function
> 2 private final function
> 12 private function
> 8 private static function
> 120 protected function
> 5 public final function
> 125 public function
> 11 public static function
> 3 static function
> 4 static private function
> 7 static protected function
> 16 static public function
>
> This is code that is 6 years old. As you can see I'm completely inconsistent.
>
> If there was some evidence that one order is preferable to another -
> pretty much ANY metric would do - then I'd probably adopt it.
>
> But I don't know if it makes ANY difference.
>
> OOI. I did the same analysis for Zend Framework (not the most recent,
> but a good a representative analysis as any I suppose).
>
> 1 abstract function
> 40 abstract protected function
> 153 abstract public function
> 1 final private function
> 1 final protected function
> 9 final public function
> 2 final public static function
> 150 private function
> 37 private static function
> 1 protected abstract function
> 1507 protected function
> 63 protected static function
> 5 public abstract function
> 2 public final function
> 11956 public function
> 701 public static function
> 1 static function
> 1 static private function
> 10 static protected function
> 60 static public function
>
> So, as mixed up as my own.
But it is good to know that at least the attributes are commutative. I was never sure about that.
Bob McConnell