In fact, this is a very easy problem to solve. In my opinion, I have been familiar with it. I recently learned how to use JavaScript to declare variables using var.
In fact, you do not need to use var declaration in PHP, but when a variable is a member variable of a class, there is no problem in using var.
When var is used externally, the following error occurs: Parse error: syntax error, unexpected T_VAR in..., for example, my error message:
Parse error: syntax error, unexpected T_VAR in D: \ Apache2.2 \ htdocs \ shirdrn \ page \ p2 \ pageUtil. inc on line 34
I'm testing: An error occurred while using a class object defined by myself as a member of the class within a class.
Address. inc code corresponding to the address class:
Copy codeThe Code is as follows:
<? Php
Class Address {
Var $ road;
Function Address (){}
Function setRoad ($ road ){
$ This-> road = $ road;
}
}
?>
The Person class and Its Test Code are as follows:
Copy codeThe Code is as follows:
<? Php
Require ("address. inc ");
Class Person {
Var $ name;
Var $ address;
Function Person (){
}
Function display (){
Echo "Name:". $ this-> name. "<BR> ";
Echo "Road:". $ this-> address-> road. "<BR> ";
}
}
Var $ p = new Person ();
$ P-> address = new Address ();
$ P-> address-> setRoad ("Chagnchun Road ");
$ P-> name = "Shirdrn ";
$ P-> display ();
?>
The test output is abnormal:
Parse error: syntax error, unexpected T_VAR in D: \ Apache2.2 \ htdocs \ shirdrn \ page \ p2 \ pageUtil. inc on line 34
This is because var is used in the person. php code to declare variables. This is not the case in PHP. As long as the "$" symbol is used to start, it indicates that the character is followed by a PHP variable.
Haha :-)
Supplemented by other netizens:
Solution: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or, two days ago, we started our php journey and made a very common website. As a result, our php version is 5.0, the server version is 4.0. I was busy for a day yesterday. This morning, I found a solution in an article. Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'. If "public" exists, remove "public. No error occurs. If "public" is the definition variable, change "public" to "var ".