PHP Exception Parse Error:syntax error, unexpected T_var fault resolution _php Tips

Source: Internet
Author: User
Tags parse error

In fact, this is a very easy to solve the problem. In my opinion, déjà vu, hehe, recently learned JavaScript but learned to use VAR to declare variables.

In fact, there is no need to use the Var declaration in PHP, but when a variable as a member of a class variable , the use of Var is not a problem.

Use VAR on the outside error 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: Inside 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:

Copy Code code as follows:

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

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

Copy Code code 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 ();
?>

An exception occurred in the Test loss:

Parse error:syntax error, unexpected T_var in D:\Apache2.2\htdocs\shirdrn\page\p2\pageUtil.inc on line 34

is because the var declaration variable is used in person.php code, which is not possible in PHP, as long as the "$" symbol is used to indicate that the character is followed by a PHP variable.
hehe:-)

Other netizens ' supplemental method:

Problem Resolution: syntax error, unexpected t_string, expecting t_old_function or t_ FUNCTION or T_var or two days before the start of their own PHP trip, do a very common website, the result of our PHP is 5.0 version, the server is 4.0 version, wondering dead slightly. Yesterday was a busy day, and this morning came, in an article found out, the solution. Parse error:syntax error, unexpected t_string, expecting t_old_function or t_function or '} ', if "public", will "pub Lic "removed. There is no error, if "public" is defined variable, change "public" to "Var".

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.