O'Reilly logo

Mastering Joomla! 1.5 Extension and Framework Development by Chuck Lanham, James Kennard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using and building getInstance() methods

Many of the core classes in Joomla! use a special method called getInstance(). There are three main reasons for using the getInstance() method:

  • It makes it easier to keep track of objects. Take the JDatabase object as an example. We can access this object at any time using the static JFactory::getDBO() method. If we were unable to do this, we would need to continually pass the object around or declare it global in every method and function that required it.
  • It helps prevent us from duplicating work. For classes that support it, we do not have to continually instantiate a new object of that type every time we need it. This helps reduce the overall work that PHP is required to complete.
  • It provides us with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required