Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialObayanju Damilare
3,383 Pointswhen do we use self ?? thanks for your answer
when and why do we use the self keyword
2 Answers
Mochammad Rezza
4,778 Pointsself used when we using static property and want to access or set current static property.
for example I have Instance class in the following code.
class Instance
{
private static $_instance;
public static function getInstance(){
if(!isset(self::$_instance)){
self::$_instance = new Database; // set variable $_instance with new object connection
}
}
}
Obayanju Damilare
3,383 PointsThanks Rezza, so basically its used to call another static method within a class