tags:

views:

41

answers:

4

I made this stupidly simple PHP file containing

<?php

class stuff {
    private $var;
}

?>

and results in this error when run:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in . . . on line 4

To make things even more confusing, it functions normally on a different domain with the same host. Surely the folder and domain have nothing to do with whether class properties can be defined. What is going on here??

+6  A: 

That's legal PHP code. I'd guess you're testing it in a machine that has PHP 4 installed. Support for PHP 4 has been discontinued for a long time; it's strongly recommended to upgrade.

Artefacto
Bam! That's the answer! Turns out I accidentally ticked a PHP 4 checkmark on the control panel for only that domain.
Vortico
I also had no idea PHP 4 didn't support classes. It's apparently had that feature for a shorter time than I though.
Vortico
@Vor It supports classes, though they're little more than arrays with methods. In particular, you cannot have private or protected members.
Artefacto
Ah, thank you. Public variables didn't seem to work in PHP 4 either.
Vortico
@Vor They're all public. The `public` keyword did not exist, though. You have to use the `var` keyword to declare them.
Artefacto
+2  A: 

Seems like PHP 4 is active on that particular domain/folder of yours.

deceze
Yup! That was the problem. Both PHP 4 and 5 were installed, but not to my knowledge at the time, 4 was set as the primary version.
Vortico
A: 

You mean a different domain hosted on the same server? It could be an error with your php installation.

Falmarri
+1  A: 

It looks like php4.

put

<?php phpinfo();> 

into a file and view it from a web browser. That will let you determine the version.

paullb
Never post short tags, not all environments have theirs on and it can make debugging code very confusing when your trying to help some one who is already confused.
Mark Tomlin
Good catch, sorry about that, changed.
paullb
Sure enough, it was PHP 4. I've enabled 5 on the server, and it works perfectly now.
Vortico