What is difference between this and self in php?
Where's the difference between Show Example: I've seen this code recently.
But I remember that
asked Dec 22, 2009 at 18:37
3
Also, you cannot normally access an instance member from a static method. Meaning, you cannot do
because the static method would not know which instance you are referring to. answered Dec 22, 2009 at 18:40
Tor ValamoTor Valamo 32.5k11 gold badges71 silver badges81 bronze badges 3
So in other words, use self for static and this for non-static members or methods.
mickmackusa 39k11 gold badges76 silver badges112 bronze badges answered Dec 22, 2009 at 18:40
YacobyYacoby 53.3k13 gold badges111 silver badges119 bronze badges
answered Dec 22, 2009 at 18:39
jldupontjldupont 89.6k56 gold badges195 silver badges310 bronze badges
Pang 9,192146 gold badges85 silver badges118 bronze badges
answered May 18, 2017 at 4:08
answered Dec 22, 2009 at 18:39
MatchuMatchu 81.9k17 gold badges151 silver badges160 bronze badges 1
answered Dec 22, 2009 at 18:42
Pascal MARTINPascal MARTIN 388k77 gold badges646 silver badges656 bronze badges $this is use to call the instance of class, where self:: is mostly used to call the constant variable within class. answered Jun 8, 2015 at 8:55
Is self and this keyword same?Technically both self and this are used for the same thing. They are used to access the variable associated with the current instance. Only difference is, you have to include self explicitly as first parameter to an instance method in Python, whereas this is not the case with Java.
What self means PHP?PHP self refers to the class members, but not for any particular object. This is because the static members(variables or functions) are class members shared by all the objecxts of the class. Whereas, $this wil refer the member variables and function for a particular instance.
What is the use of this in PHP?$this is a reserved keyword in PHP that refers to the calling object. It is usually the object to which the method belongs, but possibly another object if the method is called statically from the context of a secondary object. This keyword is only applicable to internal methods.
What is the purpose of and PHP self?In PHP, the self and this keyword are used to refer to class members within the scope of a class. The class members can be either variables or functions. These PHP keywords differ from the static behavior of the class members.
|