1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

::getInstance() - what is it for?

Discussion in 'XenForo Development Discussions' started by Arty, Jul 22, 2013.

  1. Arty

    Arty Well-Known Member

    I see that many classes in XenForo have static function getInstance() and store its instance statically.

    Is it simply a way to call non-static methods of that class without initializing more than one instance of same class? Or could it be used for something more complex?
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    Yes, it's to ensure only one instance is created. Doesn't make sense to have two XenForo_Session instances during the same run.

    As for more advanced usage, you can make some fancy boilerplate code to make a self contained class where it manages its own instances, but I have yet to see real life usage.
    Arty likes this.
  3. euantor

    euantor Well-Known Member

    LPH, tyteen4a03 and Arty like this.

Share This Page