I generally use:
function &getInstance()
{
static $instance;
if (!isset($instance)) {
$instance = new Class(); // NOT by reference
}
return $instance;
}
be wary of doing this where performance is an issue - dataobjects used something like this to store options early on. - - PEAR::getStaticProperty() ** note this could be used for singletons as well.
however after alot of profiling I realized that it was slowing down the whole application.
if you have to get the singleton of a class often it's better to stick with $GLOBALS etc.
Regards
Alan
--
Can you help out?
Need Consulting Services or Know of a Job?
http://www.akbkhome.com