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 $ 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;   

Thank you in advance

$ 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.

If you use unused assets you can directly access $ this-> Name .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -