In PHP, variables do not need to be declared with var, but when a variable is used as a member variable of a class, there is still no problem using var. Actually, this is a very easy problem to solve. In my opinion, it seems familiar, haha, I recently learned javascript but 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 Test: An error occurred when using a self-defined class object as a member of the class inside a class. 1. The address.inc code corresponding to the address class:
2, person class and test code are person.php:
The test output is abnormal: parse error: syntax error, unexpected t_var in d:apache2.2htdocsshirdrnpagep2pageutil.inc on line 34 Because var is used to declare variables in the person.php code, this cannot be done in PHP. As long as the "$" symbol is used at the beginning, it means that what follows this character is a PHP variable. Supplementary methods: Problem solved: syntax error, unexpected t_string, expecting t_old_function or t_function or t_var or I started my own PHP journey two days ago and made a very ordinary website. It turns out that our PHP is version 5.0 and the server is version 4.0. I am so confused. Solution: parse error: syntax error, unexpected t_string, expecting t_old_function or t_function or t_var or '}', if there is "public", remove "public". There will be no error. If "public" is a defined variable, change "public" to "var". |