PHP Exception parse Error:syntax error ... Error resolution method

Source: Internet
Author: User
Tags parse error
There is no need to use Var in PHP, but when a variable is a member of a class, using Var is no problem.

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.

Use VAR on the outside to error parse Error:syntax error, unexpected T_var in ..., such as 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: in the interior of a class, an error occurs when you use a class object of your own definition as a member of this class.

The address class corresponds to the Address.inc code:

The code is as follows:

<?phpclass Address {   var $road;   function Address () {}   function Setroad ($road) {    $this->road = $road;   }}? >

The person class and its test code are person.php as follows:

The code is as follows:

<?phprequire ("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 ();? >

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 to do so in PHP, as long as the "$" symbol starts with a PHP variable that is followed by the character.

  • 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.