Variables in PHP do not need to be declared with Var, but it is not a problem to use VAR when a variable is a member variable of a class. In fact, this is a very easy problem to solve. In my opinion, familiar, hehe, recently learned JavaScript has learned to use VAR declaration variables. In fact, in PHP does not need to use VAR declaration, but when a variable as a member of a class variable, the use of Var is not a problem. Using Var on the outside error parse Error:syntax error, unexpected T_var in ..., such as my error message: Parse Error:syntax error, unexpected T_var in D:\ap Ache2.2\htdocs\shirdrn\page\p2\pageutil.inc on line 34 Test: An error occurred inside a class that uses a class object of its own definition as a member of the class. The 1,address class corresponds to the Address.inc code:
- Class Address {
- var $road;
- function address () {}
- function Setroad ($road) {
- $this->road = $road;
- }
- }
- ?>
Copy CodeThe 2,person class and the test code are person.php:
- Require ("Address.inc");
- Class Person {
- var $name;
- var $address;
- function person () {
- }
- function display () {
- echo "Name:" $this->name. "
";
- echo "Road:" $this->address->road. "
";
- }
- }
- var $p = new Person ();
- $p->address = new address ();
- $p->address->setroad ("Chagnchun Road");
- $p->name = "SHIRDRN";
- $p->display ();
- ?>
Copy CodeTest output Exception: Parse Error:syntax error, unexpected T_var in D:\apache2.2\htdocs\shirdrn\page\p2\pageutil.inc on line 34 because the variable is declared in the person.php code using VAR, it is not possible in PHP, as long as the "$" sign is used to indicate that the character is followed by a PHP variable. Supplemental methods: PROBLEM Solving: syntax error, unexpected t_string, expecting t_old_function or t_function or T_var or two days before starting their own PHP tour, to do a very common site, results Our PHP is version 5.0, the server is version 4.0, I was wondering about death. Workaround: Parse Error:syntax error, unexpected t_string, expecting t_old_function or t_function or T_var or '} ', if there is "public", Remove the "public". There is no error, if "Public" is the definition variable, change "public" to "Var". |