PHP exception Parse error: syntax error... error solution

PHP中文网
Release: 2016-07-21 15:30:08
Original
1532 people have browsed it

There is no need to use var declaration in PHP, but when a variable is used as a member variable of a class, there is no problem in using var

In fact, this is a very easy problem to solve . In my opinion, it seems familiar, haha, I recently learned JavaScript and learned to use var to declare variables.

In fact, there is no need to use var declaration in PHP, but when a variable is used as a member variable of a class , there is still no problem in using var.

When using var externally, an 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. 2htdocsshirdrnpagep2pageUtil.inc on line 34

I was testing: When using a self-defined class object as a member of this class inside a class, something went wrong.

The address.inc code corresponding to the Address class:

The code is as follows:

<?php
class Address {
   var $road;
   function Address(){}
   function setRoad($road){
    $this->road = $road;
   }
}
?>
Copy after login

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

The code is 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();
?>
Copy after login

Exception occurs in test output:

Parse error: syntax error , unexpected T_VAR in D:Apache2.2htdocsshirdrnpagep2pageUtil.inc on line 34

It’s because var is used to declare variables in the person.php code. This cannot be done in PHP. Just use the "$" symbol. It means that what follows this character is a PHP variable.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!