Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PHP 4.4.9 throws 'Parse error: syntax error, unexpected T_STATIC'? [closed]

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?

like image 887
Ahmed Memon Avatar asked Jan 14 '10 21:01

Ahmed Memon


People also ask

What are syntax errors in PHP?

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as: PHP Parse error: syntax error, unexpected '{' in index.php on line 20 The unexpected symbol isn't always the real culprit.

What is unexpected $end syntax/parser error in PHP?

And Unexpected $end syntax/parser error can also occur for unterminated expressions or statements: So, look at the end of scripts first. A trailing ; is often redundant for the last statement in any PHP script. But you should have one.

What causes unexpected [ syntax errors?

Other causes for Unexpected [ syntax errors. If it's not the PHP version mismatch, then it's oftentimes a plain typo or newcomer syntax mistake: You can't use array property declarations/expressions in classes, not even in PHP 7. Confusing [ with opening curly braces { or parentheses ( is a common oversight.

How do I interpret error messages in PHP?

For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as: PHP Parse error: syntax error, unexpected '{' in index.php on line 20 The unexpected symbol isn't always the real culprit. But the line number gives a rough idea of where to start looking. Always look at the code context.


1 Answers

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!

like image 57
Matchu Avatar answered Oct 06 '22 00:10

Matchu