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.