2

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() {
// lots ...
}
2
  • 2
    Because PHP interpreter is not best in the universe :( But it's flexible so we can torment it every day to do our bidding :) Commented Feb 21, 2011 at 14:44
  • What version of PHP are you using? Commented Feb 21, 2011 at 14:45

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

@Linus Kleen: Yeah, I was searching but nothing came up. Perhaps they found it on their own and quietly fixed it. Sneaky, much ;)
@Linus @BoltClock svn.php.net/viewvc?view=revision&revision=246130 (yes, I was bored :) )
@BoltClock Can you put this in your answer, so I can accept? And thank you for productively wasting your time, @Matt.
@Linus No problem. Got to have something to do while I'm waiting for long queries to finish :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.