Jump to content

pass parameters to singleton!


xploita

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/54167-pass-parameters-to-singleton/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.