php - Using this operation -> inside and outside class -
I know how this operation works (- & gt;), but I'm just curious. As you can see from the following code when you use it within a square, then it is Thank you in advance If you use unused assets you can directly access $ this-> $ Name is , but outside of a class it's like
$ a-> attribute . So why do you first use two dollar sign ($), but second, you only use a dollar sign? I'm very curious. I can ignore it, but it is happening on my nerves.
& lt ;? Php class classname {public $ attribute; Public Function __get ($ name) {return $ this-> $ Name; }} $ A = new classname (); $ A- & gt; Attribute = "hello"; Echo $ a- & gt; Specialty; ? & Gt;
$ this - & Gt; $ Name is the class of the object in
$ this ,
$ name you have already passed the value to it, so you have declared that the
$ This- & gt; $ Name .
$ a-> Attribute which is already declared, so you are accessing the object with the property.
$ this-> Name .
Comments
Post a Comment