What is the difference between $this and self in PHP? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between $this and self in PHP?

OOPs concept, PHP, $this, self

23rd Sep 2019, 8:07 PM
Kapil Dev
Kapil Dev - avatar
1 Answer
+ 8
Of course $this points to the current instance of a class. self keyword is used to access class constants, static variables and functions. Examples: $this->height; $this->calculate(); self::DEFAULT_VALUE; self::$staticVar; self::staticMethod() ;
25th Sep 2019, 9:00 PM
Igor Makarsky
Igor Makarsky - avatar