Answer the question
In order to leave comments, you need to log in
Explain this.x=x //?
I admit right away I don’t understand the concepts of OOP and I’m completely zero in programming.
I meet this in the code and get lost. I suspect I'm not the only one. Perhaps someone will be able to explain for the "general audience", so to speak, in "plain language" how to understand (and use) the this keyword. Those. interested in the foundation, examples are welcome if they help open the eyes of a beginner.
Regarding the title: I gave an example that was the last straw in this matter. public yyy (xxx x) {this.x=x; ...} in c# , but you can do it in any language (syntax is not a problem). Key question: ESSENCE of this.
Answer the question
In order to leave comments, you need to log in
As the name implies, this is a pointer to this same instance of the class that we are currently in.
In this example, the method probably receives a parameter named x, and its existence sets off a class field with the same name - and in order to see both, the programmer is forced to specify this.x (class field) = x (variable in the function or its parameter)
in PHP $this
it is, in fact, a reference, a pointer to a class instance within the same class instance, available only in the class instance.
a kind of replacement for passing an instance to your own methods as a parameter or property.
correct me if I'm wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question