PHP5 static keyword and usage
The static
keyword is known to be a free agent.
You can declare a method "static" either by writing:
protected static function foo() {
// lots of self:: code in here
}
Or:
static protected function bar() {
// lots of self:: code in here
}
I just came across code that read:
static protected static function foobar() {
// lots of self:: code in here
}
Surely it's a typo from the original author, but why is PHP accepting this as a valid statement?
UPDATE The version in question is PHP 5.2.16. I just confirmed, this is valid too:
static static static public static function foobar(开发者_如何学JAVA) {
// lots ...
}
That appears to be a bug in previous versions of PHP which has been fixed. Testing it in PHP 5.3 yields
Fatal error: Multiple static modifiers are not allowed
EDIT: thanks to Matt Gibson for the find, this was indeed a bug that was fixed somewhere in the PHP 5.3 branch.
精彩评论