Answer the question
In order to leave comments, you need to log in
What is the difference between self and "ClassName"?
class A {
public static $var = 1;
public function hello() {
echo self::$var;
echo A::$var;
}
}
Answer the question
In order to leave comments, you need to log in
A::$var
call in the context of class A
call in the context of a class in which there is definitely (in this case class A)
a call in the context of the current class,
i.e. in the case of inheritance:
- if you have a class B that is inherited from class A and in which $ will be redefined var, it will be used,
- in the case of self, the variable will be used from where self is called
, i.e. nothing in your particular case, but it is better to use static
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question