xploita Posted June 4, 2007 Share Posted June 4, 2007 following this article on the Observer Pattern: http://mesoimpact.com/articles/errorHandling.html i in the following class,i use the getinstance to instantiate other classes,however,i can not seem to pass any parameters to the instantiated classes. class Singleton{ function &getInstance ($class, $name = NULL){ static $registry = array(); $_instanceName = is_null($name) ? $name : $class; if ( !isset($registry[$class][$_instanceName]) || !is_object($registry[$class][$_instanceName]) ) { $registry[$class][$_instanceName] =& new $class; } return $registry[$class][$_instanceName]; } # end method } for example,i want to use the getinstance to have an instance of the class ERRORS,at the same time pass some parameters to the ERRORS class' constructor. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/54167-pass-parameters-to-singleton/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.