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.