PHP exception Parseerror: syntaxerror, unexpected error Solution

Source: Internet
Author: User
Tags parse error
PHP does not need to use var declaration at all, but when a variable acts as a member variable of a class, there is no problem with using var. in PHP, you do not need to use var declaration. However, when a variable acts as a member variable of a class, there is no problem with using var.

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:

The Code is as follows:

 road = $road;   }}?>

The Person class and Its Test Code are as follows:

The Code is as follows:

 name."
"; echo "Road : ".$this->address->road."
"; }}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.

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.