PHP Exception Parse Error:syntax error, unexpected t_var wrong how to solve

Source: Internet
Author: User
Tags parse error

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:

    1. Class Address {
    2. var $road;
    3. function address () {}
    4. function Setroad ($road) {
    5. $this->road = $road;
    6. }
    7. }
    8. ?>
Copy Code

The 2,person class and the test code are person.php:

    1. Require ("Address.inc");
    2. Class Person {
    3. var $name;
    4. var $address;
    5. function person () {
    6. }
    7. function display () {
    8. echo "Name:" $this->name. "
      ";
    9. echo "Road:" $this->address->road. "
      ";
    10. }
    11. }
    12. var $p = new Person ();
    13. $p->address = new address ();
    14. $p->address->setroad ("Chagnchun Road");
    15. $p->name = "SHIRDRN";
    16. $p->display ();
    17. ?>
Copy Code

Test 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".

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.