For php object-oriented issues, please refer to the following code, which is very simple. please take a moment to look at it:
Class person {public $ name; public function _ construct () {$ this-> $ name = 'Tom '; // code 1 }}$ a = new person (); echo $ a-> name;
Running the code above will report an error of 'variable undefined.
Why is this error reported?
If you change code 1 to $ this-> name = 'Tom ', no error is reported.
Does the dollar sign have any special significance? What is the difference between a dollar sign and a dollar sign?
Thank you.
Reply to discussion (solution)
Let's talk about it:
Differences between $ name and $ name
$ This-> name attribute of the name class
$ This-> $ name attribute of the $ name class. because you have not defined the variable $ name first, an error is returned.
Variable
If $ name = 'Hello'
$ This-> $ name is equivalent to $ this-> hello