5

I just realized the professor Google is unable to present a specific page where I can find out, when static keyword added to PHP 4. Though following the change log for php 4 I can see that it was available since Version 4.0.6 (or before) but why does it throws:

Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in {FILE_PATH+LINE#}

for a simple code as follows:

class myClass
{
    static $_debug = true;
}

Or this assignment of class-variable was introduced in earlier versions of PHP?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Ahmed Memon
  • 219
  • 3
  • 11
  • 1
    What you see in the PHP 4 changelog are references to static methods, not the `static` keyword. – Pekka Jan 14 '10 at 21:09
  • for those who doubt if static is something specific to php5.x, checkout http://www.sfr-fresh.com/unix/www/php-4.4.9.tar.gz:a/php-4.4.9/Zend/zend_language_parser.c – Ahmed Memon Jan 14 '10 at 21:14

1 Answers1

14

I'm pretty sure static class variables are new to PHP5, so can't be used in PHP4.

Here's the deal: PHP4 can use the static keyword in functions, not classes. The only PHP4 usage of static was like this:

function howManyTimes() {
    static $count = 0;
    echo "Function has been called $count times.";
    $count++;
}

That variable is bound to the function's scope forever. That's how PHP4 interprets static. The PHP5 interpretation you are trying to use is not available in your current PHP version. Sorry!

Matchu
  • 83,922
  • 18
  • 153
  • 160
  • 1
    +1 Yup - public/private/protected and static are PHP 5 only I believe. – John Parker Jan 14 '10 at 21:08
  • 1
    True that. Static is PHP 5 specific. – Pekka Jan 14 '10 at 21:08
  • http://www.sfr-fresh.com/unix/www/php-4.4.9.tar.gz:a/php-4.4.9/Zend/zend_language_parser.c – Ahmed Memon Jan 14 '10 at 21:15
  • ...I'm confused as to what that link is for. Are you saying I'm wrong? – Matchu Jan 14 '10 at 21:28
  • Thanks for the answer and for all of the participants. Infact, like most of the functions PHP guys should have clearly mentioned it somewhere. I just downloaded the php 4.4.9 and checked my self and php 4.4.9 was like yaikh! no static keyword was recognized there. Regards!! – Ahmed Memon Jan 14 '10 at 21:36