PHP 4.4.9 throws ‘Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’’

Today, my website decided suddenly not to work and reported a syntax error however I had not made any changes to it. It gave me an error message

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

… I looked at all the braces and keywords and they all checked out fine. I looked at phpinfo() and found my PHP5.* had been downgraded to PHP4.* however this did not explain why the script did not work. I wrote this test class

<?php
class TestClass
{
	static $instance;
}
?>

and to my surprise it threw the same error message as my website.

Here is the solution: PHP4.* does support the ‘static’ keyword however it supports it in the scope of a function and not in a ‘class’, example

<?php
function testFunction()
{
	static $instance = 0;
	echo "Instance value " . $instance;
	$instance++
}
?>

So, only way to fix this is to upgrade to PHP5 which I did.

Advertisements

One thought on “PHP 4.4.9 throws ‘Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s