lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at
PHP: Singleton Pattern for Composed Objects
I usually use a variation of the method below in classes that include a composed object (e.g., a database object):

// method: load composed object
function _load_object()
// already loaded
if ( is_object($this->ComposedObject) ) return;


// create composite object
$this->ComposedObject = new ComposedObject();
// add additional config steps here

// END method

For an example, see the _load_phpmailer method in my CeoFramework class.